我正在尝试为VBA编写一个宏,它将根据您告诉它搜索的特定字符串搜索文件目录,但前提是该字符串存在于一系列单元格中。
到目前为止,我已经完成了大部分功能,但问题在于让程序实际返回文档。
Public Function Method2(ByVal rngl As Range, ByVal strSearch As Variant)
Dim directory As String
Dim fileName As String
Dim objWord
Dim objDoc
Dim rng1 As Range
directory = "S:\File Recipes\NEW IWAVE RECIPES"
fileName = "test"
Set objWord = CreateObject("Word.Application")
Set rng1 = Range("A:A").find(strSearch, , xlValues, xlWhole)
If Not rng1 Is Nothing Then
MsgBox "Product Codes Found!"
fileName = Dir(directory & "*.docx")
MsgBox (fileName)
' Set objDoc = objWord.Documents.Open(fileName)
objWord.Visible = True
Else
MsgBox "Product Codes Not Found!"
End If
End Function
据我所知,问题在于:
fileName = Dir(directory & "*.docx")
没有任何反馈:
MsgBox (fileName)
即使找到了一个字符串。
非常感谢任何帮助。