初學VBA(一)打開PDF文件


打開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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM