打开PDF文件的两种方法
1.用Shell
优点是可以指定PDF文件的打开方式
缺点是有硬编程
1 Sub RunPDFWithExe() 2 MyPath = "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\AcroRd32.exe" 3 MyFile = "W:\MyWork\BIPSmart\20161116\sample.pdf" 4 Shell MyPath & " " & MyFile, vbNormalFocus 5 End Sub 6 7 Private Sub Worksheet_SelectionChange(ByVal Target As Range) 8 Dim targetVal As String 9 10 targetVal = ActiveCell.Value 11 12 13 If targetVal <> "" Then 14 Call RunPDFWithExe 15 Else 16 MsgBox "no data" 17 Exit Sub 18 End If 19 End Sub
2.用超链接方式
缺点是只能使用系统默认的PDF打开方式。
1 Private Sub Worksheet_Activate() 2 With Sheet1 3 .Hyperlinks.Add Anchor:=.Range("a5"), _ 4 Address:="W:\MyWork\BIPSmart\20161116\sample.pdf", _ 5 ScreenTip:="PDF", _ 6 TextToDisplay:="PDF" 7 End With 8 End Sub