我创建了以下函数来从我的 winform 上的按钮打开 .pdf 文件:
Function OpenReports(fileName As String) As String
Dim xlWBPath As String
Try
xlWBPath = Globals.ThisWorkbook.Application.ActiveWorkbook.Path
System.Diagnostics.Process.Start(xlWBPath & "\fileName")
Catch ex As Exception
MsgBox("The " & fileName & "is not found on directory")
End Try
Return ""
End Function
当我在这里调用函数时:
Private Sub btnRptEmployeePayToMarket_Click(sender As Object,
e As EventArgs) Handles btnRptEmployeePayToMarket.Click
OpenReports("Ranges to Market.pdf")
End Sub
它进入错误陷阱。它找不到文件。但是,如果我不运行该函数,而是将其作为 Private Sub 执行,如下所示:
Private Sub btnRptEmployeePayToMarket_Click(sender As Object, e As EventArgs) Handles btnRptEmployeePayToMarket.Click
Dim xlWBPath As String
Try
xlWBPath = Globals.ThisWorkbook.Application.ActiveWorkbook.Path
System.Diagnostics.Process.Start(xlWBPath & "\Ranges to Market.pdf")
Catch ex As Exception
MsgBox("The file Ranges to Market.pdf is not found on directory")
End Try
End Sub
然后它工作正常。所以我认为它与我的功能有关,但我无法弄清楚它是什么。