View Single Post
 
Old 03-03-2017, 10:05 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

An Excel function? I thought you wanted to insert the PDF into Word? If you put a macrobutton field where you want the PDF. The size of the PDF will be determined by the distance between the margins at that point.

{ MACROBUTTON InsertPDF Click to select and insert PDF file }

and double click that field to run the InsertPDF macro below, it will insert the selected PDF at the field location
Code:
Sub InsertPDF()
'Graham Mayor - http://www.gmayor.com - Last updated - 04/03/2017
Dim strPDF As String
Dim oRng As Range
    Set oRng = Selection.Range
    strPDF = BrowseForFile
    If Not strPDF = vbNullString Then
        oRng.Text = ""
        ActiveDocument.InlineShapes.AddOLEObject _
                ClassType:="AcroExch.Document.DC", _
                FileName:=strPDF, _
                LinkToFile:=False, _
                DisplayAsIcon:=False, _
                Range:=oRng
    End If
lbl_Exit:
    Exit Sub
End Sub

Private Function BrowseForFile() As String
'Graham Mayor - http://www.gmayor.com - Last updated - 04/03/2017
Dim fDialog As FileDialog
    On Error GoTo Err_Handler
    Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
    With fDialog
        .Title = "Select the document to insert"
        .AllowMultiSelect = False
        .Filters.Clear
        .Filters.Add "PDF Format", "*.pdf"
        .InitialView = msoFileDialogViewTiles
        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