ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Insert/Embed PDF File automatically via VBA (https://www.excelbanter.com/excel-programming/415193-insert-embed-pdf-file-automatically-via-vba.html)

Brad

Insert/Embed PDF File automatically via VBA
 
I'm trying to create a little program where it will allow a user to embed a
PDF file so we can maintain records. I've done the record macro and recorded
the action of Insert-Object-Create from File, however it forces you to
select a file. And in the code, it puts the file name you select. This is an
issue as the user may save the PDF file as a different name than
preprogrammed. So is it possible to have VBA automatically open the
Insert-Object-Create from File-Browse file box to allow the user to select
the PDF file? Below is the code to automatically add a prenamed PDF file and
it works fine, just doesn't give the user the option to select the file they
want to insert. Thanks in advanced.

------------------------
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 8/5/2008 by bhodge
'

'
ActiveSheet.OLEObjects.Add(Filename:= _
"C:\Documents and Settings\bhodge\Desktop\test2.pdf", Link:=False, _
DisplayAsIcon:=True, IconFileName:= _

"C:\WINDOWS\Installer\{AC76BA86-7AD7-1033-7B44-A70000000000}\PDFFile.ico", _
IconIndex:=0, IconLabel:= _
"C:\Documents and Settings\bhodge\Desktop\test2.pdf").Select
End Sub



Ak Man

Insert/Embed PDF File automatically via VBA
 
MsgBox "Enter the your file"
MyFile = Application.GetOpenFilename
If MyFile = "False" Then Exit Sub

HTH
--
Ak


"Brad" wrote:

I'm trying to create a little program where it will allow a user to embed a
PDF file so we can maintain records. I've done the record macro and recorded
the action of Insert-Object-Create from File, however it forces you to
select a file. And in the code, it puts the file name you select. This is an
issue as the user may save the PDF file as a different name than
preprogrammed. So is it possible to have VBA automatically open the
Insert-Object-Create from File-Browse file box to allow the user to select
the PDF file? Below is the code to automatically add a prenamed PDF file and
it works fine, just doesn't give the user the option to select the file they
want to insert. Thanks in advanced.

------------------------
Sub Macro3()
'
' Macro3 Macro
' Macro recorded 8/5/2008 by bhodge
'

'
ActiveSheet.OLEObjects.Add(Filename:= _
"C:\Documents and Settings\bhodge\Desktop\test2.pdf", Link:=False, _
DisplayAsIcon:=True, IconFileName:= _

"C:\WINDOWS\Installer\{AC76BA86-7AD7-1033-7B44-A70000000000}\PDFFile.ico", _
IconIndex:=0, IconLabel:= _
"C:\Documents and Settings\bhodge\Desktop\test2.pdf").Select
End Sub




All times are GMT +1. The time now is 11:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com