View Single Post
 
Old 06-22-2016, 07:49 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Bearing in mind that not all PDF format files are editable in Word, and that this only works for Word versions 2013 and later, the following can be used to select and open one

Code:
Option Explicit

Sub Macro1()
Dim strFname As String
Dim oDoc As Document
    strFname = BrowseForFile("Select the PDF file to open")
    If strFname = vbNullString Then GoTo lbl_Exit
    Set oDoc = Documents.Open(strFname)
    'do stuff with odoc
lbl_Exit:
    Exit Sub
End Sub

Function BrowseForFile(Optional strTitle As String) As String
'Graham Mayor - http://www.gmayor.com
'strTitle is the title of the dialog box
'Set bExcel value to True to filter the dialog to show Excel files
'The default is to show Word files
Dim fDialog As FileDialog
    On Error GoTo err_handler
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = strTitle
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "Adobe PDF files", "*.pdf"
        .InitialView = msoFileDialogViewList
        If .Show <> -1 Then GoTo err_handler:
        BrowseForFile = fDialog.SelectedItems.Item(1)
    End With
lbl_Exit:
    Exit Function
err_handler:
    BrowseForFile = vbNullString
    Resume lbl_Exit
End Function
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote