vba代码可以一次打开多个文件吗?

时间:2019-06-11 09:32:32

标签: vba

我的代码如下,但我很困惑。它应该打开包含一个短语的多个pdf,但是代码只是运行而没有任何反应。 您可以同时运行同一代码来搜索并打开多个文件吗?如果有一个批处理代码可以做到这一点,

我终于找到了答案。 @Damian感谢您的帮助

Sub OpenPdf()

On Error GoTo OpenPdf_Error

Dim pdfname As String
Dim pdf
Const sPath = "S:\RA QUOTES 2019"
Dim FName As String
Dim arNames() As String
Dim myCount As Integer
Dim i As Integer

FName = Dir("S:\RA QUOTES 2019\*.pdf*")
Do Until FName = ""
    myCount = myCount + 1
    ReDim Preserve arNames(1 To myCount)
    arNames(myCount) = FName
    FName = Dir
    Loop


pdfname = Application.InputBox("Enter the pdf you are looking for")
pdfname = "PLQ" & pdfname




For i = 1 To UBound(arNames)

If IsInArray(pdfname, arNames(i)) Then

ThisWorkbook.FollowHyperlink sPath & arNames(i)

 End If

Next i

On Error GoTo 0
Exit Sub

OpenPdf_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure 
OpenPdf"

End Sub

输出应该打开包含用户输入的pdf。这段代码只是运行,什么也没发生

1 个答案:

答案 0 :(得分:0)

大家好,我找到了答案。问题是下面的行

If InStr(1, arNames(i), pdfname, vbTextCompare)