织梦CMS - 轻松建站从此开始!

技术无忧网 - 技术从此无忧 -- 一站式中文IT技术网站 - www.tech51.net

Word 2003 使用技巧(2)

时间:2009-01-04 14:00来源: 作者: 点击:
从选定的形状返回名称和索引号 下面的过程演示了如何返回选定 Shape 对象的名称和索引号。例如,如果您需要访问代码中的特定形状对象,并需要名称或

从选定的形状返回名称和索引号

下面的过程演示了如何返回选定 Shape 对象的名称和索引号。例如,如果您需要访问代码中的特定形状对象,并需要名称或索引,那么这就非常有用。

Sub ReturnShapeData()
    Dim ShapeName As String 'Name
    Dim i As Integer
    ShapeName = Selection.ShapeRange.Name
    For i = 1 To ActiveDocument.Shapes.Count
       If ActiveDocument.Shapes(i).Name = ShapeName Then
          MsgBox "Shape " & Chr(34) & ShapeName & Chr(34) & " is Shape " & i
       End If
       Exit For
    Next i
End Sub 

将短日期转换为完整日期格式

以下代码用于将日期从 ##/##/#### 格式更改为完整日期格式。例如,将 10/20/2004 改为 2004 年 10 月 20 日星期三。

Sub ChangeDate()
   With Selection.find
      .Text = "[0-9]{2}/[0-9]{2}/[0-9]{4}"
      .MatchWildcards = True
      While .Execute
         Selection.Text = Format(Selection.Text, "DDDD d. MMMM YYYY")
         Selection.Collapse direction:=wdCollapseEnd
      Wend
   End With
End Sub 

使用文件名填充列表框

以下过程搜索指定目录,并使用找到的文件名填充一个列表对话框。

Sub ListFilenames()
   Dim strMyFile As String
   Dim lngCounter As Long
   Dim DirectoryListArray() As String
   ReDim DirectoryListArray(1000)
   strMyFile = Dir$("c:\docs\*.*")
   Do While strMyFile <> ""
      DirectoryListArray(lngCounter) = strMyFile
      strMyFile = Dir$
      lngCounter = lngCounter + 1
   Loop
   ReDim Preserve DirectoryListArray(lngCounter - 1)
   Frm.lstNormals.List = DirectoryListArray
End Sub 

确定文件是否存在

以下示例检查目录中是否存在文件。如果 Dir 函数返回一个长度为零的字符串,表示未找到该文件,并显示消息框。如果 Dir 函数找到此文件,则显示一个相应的消息框。

Sub DoesFileExist(SearchFile As String)
   Dim FileInQuestion As String
    FileInQuestion = Dir(SearchFile)
   If FileInQuestion = "" Then
      MsgBox "No such file!"
   Else
      MsgBox "File exists!"
   End If
End Sub

 
(责任编辑:admin)

织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片