Hello,
I’ve been using the VBA code included below to embed pdf files into Word documents.
I have recently discovered that when I do this the packager associates the file with the PDF reader application on the system used to embed the file.
Later, if someone with a different reader tries to open the file, it simply fails to open with no message; so other people can't open the file.
It is possible to embed the file by clicking ‘Inset>Object’ and the selecting ‘package’ and also choosing the display a icon option. When I do this manually, the file is embedded without the association, and can be opened in whatever reader the user has installed.
How can I do this in VBA? So that I can automate the clicks away?
Any help very gratefully received!
Private Sub InsertFileButton_Click()
' Browse & Select File
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Title = "Select file to insert"
.InitialFileName = "\\c:\tempFolder\"
.Filters.Clear
.Filters.Add "PDF files", "*.pdf"
.Filters.Add "all files", "*.*"
If .Show = True Then
FiletoInsert = .SelectedItems(1)
Else
Exit Sub
End If
End With
' Embed File Inline
Application.Selection.InlineShapes.AddOLEObject _
FileName:=FiletoInsert, _
LinkToFile:=False, _
DisplayAsIcon:=True, _
IconLabel:=Right(FiletoInsert, Len(FiletoInsert) - InStrRev(FiletoInsert, "\")), _
Range:=Application.Selection.Range.Next(Unit:=wdCell, Count:=1)
End Sub
Bookmarks