如何列出文件夹中的所有文件名(.wav文件)并在Word文档中创建超链接?

时间:2014-03-07 19:38:49

标签: vba ms-word word-vba

我想列出文件夹中的每个文件名(.wav文件)并创建一个超链接。类似下图:

enter image description here

我发现了这段代码,但我无法对其进行调整。

Dim MyPath As String
Dim MyName As String

 With Dialogs(wdDialogCopyFile)
 If .Display() <> -1 Then Exit Sub
 MyPath = .Directory
 End With

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
Selection.TypeText Text:=MyName & "                     "
Selection.InlineShapes.AddPicture "C:\loudspeaker.jpg", True, True
ActiveDocument.Hyperlinks.Add Anchor:=Selection.Range, Address:=MyName, TextToDisplay:=myImage   &    vbCr
 Selection.InsertAfter MyName & "      "
MyName = Dir
Loop
 Selection.Collapse wdCollapseEnd
End Sub

0 个答案:

没有答案