我创建了以下函数来从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
然后它工作正常。所以我认为它与我的功能有关,但我无法弄清楚它是什么。