Embed a PDF document and rename

Sumeluar

Active Member
Joined
Jun 21, 2006
Messages
271
Office Version
  1. 365
  2. 2016
  3. 2010
Platform
  1. Windows
  2. MacOS
  3. Mobile
Good day to all.

I have the below code that embeds a PDF document of my choice and changes the icon as per indicated path, up to there is all good. What I need assistance with is two things, one to have a popup message asking me to enter the desired name and to change the embedded document properties by making it transparent and without borders.

#
Sub InsertPDF()

Dim ChangeIcon As String, fullFileName As String

ChangeIcon = "E:\Icons\Reader.ico"

ActiveSheet.OLEObjects.Add(Filename:=Application.GetOpenFilename, _
Link:=False, _
DisplayAsIcon:=True, _
IconFileName:=ChangeIcon, _
IconIndex:=0, _
IconLabel:="Embeded Doc.").Select

End Sub
#

All ideas are greatly appreciated, thank you all before hand.

Warm regards, Sumeluar.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try the following...

VBA Code:
Sub InsertPDF()

    Dim fullFileName As Variant
    fullFileName = Application.GetOpenFilename( _
        FileFilter:="PDF File (*.pdf), *.pdf", _
        Title:="Select PDF file", _
        ButtonText:="Select")
        
    If fullFileName = False Then Exit Sub

    Dim ChangeIcon As String
    ChangeIcon = "E:\Icons\Reader.ico"
    
    Dim embeddedPdfFile As OLEObject
    Set embeddedPdfFile = ActiveSheet.OLEObjects.Add( _
        Filename:=fullFileName, _
        Link:=False, _
        DisplayAsIcon:=True, _
        IconFileName:=ChangeIcon, _
        IconIndex:=0, _
        IconLabel:="Embeded Doc.")
        
    With embeddedPdfFile
        .ShapeRange.Fill.Transparency = 1
        .Border.LineStyle = xlNone
    End With

End Sub

Hope this helps!
 
Upvote 0
Try the following...

VBA Code:
Sub InsertPDF()

    Dim fullFileName As Variant
    fullFileName = Application.GetOpenFilename( _
        FileFilter:="PDF File (*.pdf), *.pdf", _
        Title:="Select PDF file", _
        ButtonText:="Select")
       
    If fullFileName = False Then Exit Sub

    Dim ChangeIcon As String
    ChangeIcon = "E:\Icons\Reader.ico"
   
    Dim embeddedPdfFile As OLEObject
    Set embeddedPdfFile = ActiveSheet.OLEObjects.Add( _
        Filename:=fullFileName, _
        Link:=False, _
        DisplayAsIcon:=True, _
        IconFileName:=ChangeIcon, _
        IconIndex:=0, _
        IconLabel:="Embeded Doc.")
       
    With embeddedPdfFile
        .ShapeRange.Fill.Transparency = 1
        .Border.LineStyle = xlNone
    End With

End Sub

Hope this helps!
Domenic - Thanks for the prompt reply, half ways there as the embedded document does not give the option of a custom name.
 
Upvote 0
The desired name for your embedded PDF document?
Domenic - I need the ability to enter a custom name for the document, all the documents embedded are currently showing the same name "Embeded Doc.".
 
Upvote 0
Domenic - I need the ability to enter a custom name for the document, all the documents embedded are currently showing the same name "Embeded Doc.".
1700932864470.png
 
Upvote 0
Okay, try the following instead...

VBA Code:
Sub InsertPDF()

    Dim fullFileName As Variant
    fullFileName = Application.GetOpenFilename( _
        FileFilter:="PDF File (*.pdf), *.pdf", _
        Title:="Select PDF file", _
        ButtonText:="Select")
       
    If fullFileName = False Then Exit Sub
   
    Dim embeddedFileName As String
    Do
        embeddedFileName = VBA.InputBox("Enter custom PDF filename.", "PDF Filename")
        If StrPtr(embeddedFileName) = 0 Then Exit Sub
    Loop Until Len(embeddedFileName) > 0

    Dim ChangeIcon As String
    ChangeIcon = "E:\Icons\Reader.ico"
   
    Dim embeddedPdfFile As OLEObject
    Set embeddedPdfFile = ActiveSheet.OLEObjects.Add( _
        Filename:=fullFileName, _
        Link:=False, _
        DisplayAsIcon:=True, _
        IconFileName:=ChangeIcon, _
        IconIndex:=0, _
        IconLabel:=embeddedFileName)
       
    With embeddedPdfFile
        .ShapeRange.Fill.Transparency = 1
        .Border.LineStyle = xlNone
    End With

End Sub

Hope this helps!
 
Upvote 0
Solution
Okay, try the following instead...

VBA Code:
Sub InsertPDF()

    Dim fullFileName As Variant
    fullFileName = Application.GetOpenFilename( _
        FileFilter:="PDF File (*.pdf), *.pdf", _
        Title:="Select PDF file", _
        ButtonText:="Select")
      
    If fullFileName = False Then Exit Sub
  
    Dim embeddedFileName As String
    Do
        embeddedFileName = VBA.InputBox("Enter custom PDF filename.", "PDF Filename")
        If StrPtr(embeddedFileName) = 0 Then Exit Sub
    Loop Until Len(embeddedFileName) > 0

    Dim ChangeIcon As String
    ChangeIcon = "E:\Icons\Reader.ico"
  
    Dim embeddedPdfFile As OLEObject
    Set embeddedPdfFile = ActiveSheet.OLEObjects.Add( _
        Filename:=fullFileName, _
        Link:=False, _
        DisplayAsIcon:=True, _
        IconFileName:=ChangeIcon, _
        IconIndex:=0, _
        IconLabel:=embeddedFileName)
      
    With embeddedPdfFile
        .ShapeRange.Fill.Transparency = 1
        .Border.LineStyle = xlNone
    End With

End Sub

Hope this helps!
Domenic - Thank you for the quick solution, exactly what I was looking for.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,975
Members
449,095
Latest member
Mr Hughes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top