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