Excel 从其他目录/文件夹打开pdf文件
我正在使用Microsoft Office Professional Plus 2013中的Excel版本Excel 从其他目录/文件夹打开pdf文件,excel,vba,pdf,Excel,Vba,Pdf,我正在使用Microsoft Office Professional Plus 2013中的Excel版本 使用Excel VBA,我想启动Adobe Reader席,打开位于另一个文件夹中的PDF文件。 如果Excel文件和Adobe Reader文件位于同一文件夹中,我可以成功打开Adobe Reader文件。以下是有效的代码: Dim ABCfilename As String Dim returnAcrobatfile As Variant ABCfilename = "ABC.pdf"
使用Excel VBA,我想启动Adobe Reader席,打开位于另一个文件夹中的PDF文件。 如果Excel文件和Adobe Reader文件位于同一文件夹中,我可以成功打开Adobe Reader文件。以下是有效的代码:
Dim ABCfilename As String
Dim returnAcrobatfile As Variant
ABCfilename = "ABC.pdf"
acrobatFile = ThisWorkbook.Path & Application.PathSeparator & ABCfilename
returnAcrobatfile = Shell("C:\Program Files\Adobe\Reader _
11.0\Reader\AcroRd32.exe " & acrobatFile, vbNormalFocus)
不过,我想启动Adobe Reader并对其进行编程,以打开位于不同文件夹中的pdf文件
我的Excel文件位于名为C:\Customers\Pricing的文件夹中\
我的Adobe文件位于名为Z:\XYZ Company的文件夹中\
如何修改以ReturnAcrobat文件开头的代码行,以便它打开位于Z:\XYZ公司的pdf文件?请参阅下面的代码
Sub PDF_Picker()
Dim Acrobatfile As String
Acrobatfile = GetFile
Runit (Acrobatfile)
End Sub
Sub Runit(FileName As String)
Dim Shex As Object
Dim tgtfile As String
Set Shex = CreateObject("Shell.Application")
tgtfile = FileName
Shex.Open (tgtfile)
End Sub
Function GetFile()
With Application.FileDialog(msoFileDialogFilePicker)
.InitialFileName = ActiveWorkbook.Path & Application.PathSeparator
.AllowMultiSelect = False
.Title = "Select PDF Files"
.Filters.Clear
.Filters.Add "Adobe PDF Files", "*.pdf"
.InitialView = msoFileDialogViewDetails
If .Show = True Then
GetFile = .SelectedItems(1)
Else
GetFile = False
End If
End With
End Function
如果客户端将Acrobat安装在与硬编码路径不同的位置,则解决方案将失败。我对其进行了调整,使其更加健壮,并使用PDF的默认应用程序选择。顺便说一句,如果您在函数GetFile:.Filters.Add Adobe PDF Files,*.PDF中删除/删除过滤器
你可以用它打开任何文件,甚至是我刚刚测试过的MP3。
感谢tigeravatar,我从这篇文章中为您的目的调整了他的功能:
这篇文章将归功于user1302114改编的RunIt Sub:
将此工作簿的路径更改为正确的路径。您应该将以acrobatFile开头的代码行更改为正确的路径。谢谢Comintern&Kevin。它工作得很好!非常感谢gokool108。我也会试试你的方法。