gpt4 book ai didi

vb.net - 打开.pdf文件的功能而不是打开文件

转载 作者:行者123 更新时间:2023-12-04 04:47:59 24 4
gpt4 key购买 nike

我创建了以下函数来从我的 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

然后它工作正常。所以我认为它与我的功能有关,但我无法弄清楚它是什么。

最佳答案

如果您的代码示例正是您在程序中使用它的方式,那么您的函数有一个错误,它应该如下所示:

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

您使用的是字符串 "\filename"不向变量添加反斜杠 "\" & filename

关于vb.net - 打开.pdf文件的功能而不是打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17899350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com