+ Reply to Thread
Results 1 to 8 of 8

VBA Insert PDF File as an Object using User Form

  1. #1
    Registered User
    Join Date
    08-03-2015
    Location
    Egypt
    MS-Off Ver
    2013
    Posts
    5

    Question VBA Insert PDF File as an Object using User Form

    Hiii EveryONE, this my Firs post here I have problem killing me and I have to make this userform but I face this challenge i need to insert a button that will allow the user to browse and choose a PDF file this file will inserted in a cell in a sheet as an object .i try this code but it only browse and open .:


    Private Sub CommandButton4_Click()

    Dim f As FileDialog
    Set f = Application.FileDialog(msoFileDialogFilePicker)
    With f
    .Title = "Select a file..."
    .InitialFileName = "t:\" '<- start in folder
    .ButtonName = "Select"
    .Filters.Add "PDF Files", "*.PDF", 1
    .AllowMultiSelect = False
    If .Show = -1 Then
    Shell "cmd /c " & """" & .SelectedItems(1) & """"
    End If
    End With

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: VBA Insert PDF File as an Object using User Form

    Hi there,

    Try the following code and see if it does what you need:

    Please Login or Register  to view this content.
    The selected PDF file will be inserted at the currently-active cell.

    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    08-03-2015
    Location
    Egypt
    MS-Off Ver
    2013
    Posts
    5

    Re: VBA Insert PDF File as an Object using User Form

    First of all thanks for replay but it doesent work give a Run-Time error "1004": cannot insert object
    Last edited by Eng.Hashem; 08-24-2015 at 08:38 AM.

  4. #4
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA Insert PDF File as an Object using User Form

    The code inserts it in the activecell providing that cell is NOT locked and the sheet is NOT protected.

    I use this code in ThisWorkbook object so that all my sheets can be modified by code. Change ken to your password.
    Please Login or Register  to view this content.

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: VBA Insert PDF File as an Object using User Form

    Hi again,

    Has Kenneth's suggestion solved the problem?

    Regards,

    Greg M

  6. #6
    Registered User
    Join Date
    08-03-2015
    Location
    Egypt
    MS-Off Ver
    2013
    Posts
    5

    Re: VBA Insert PDF File as an Object using User Form

    Sorry my Friends the same error Cannot insert the object , lets just focus trying to insert the object fill in specific cell say "a1" PLZ .

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,481

    Re: VBA Insert PDF File as an Object using User Form

    Hi again,

    The following code works perfectly on a protected worksheet on my system:

    Please Login or Register  to view this content.
    Hope this helps - please let me know how you get on.

    Regards,

    Greg M

  8. #8
    Forum Expert Kenneth Hobson's Avatar
    Join Date
    02-05-2007
    Location
    Tecumseh, OK
    MS-Off Ver
    Office 365, Win10Home
    Posts
    2,573

    Re: VBA Insert PDF File as an Object using User Form

    Obviously, you would have to execute the protection code that I showed you or add it and then close and open your workbook for the Workbook's Open event to execute it.

    If you want it inserted to A1, then before OleObjects.Add line, Range("A1").Select. Or, we could insert it anywhere and then move it.

    I guess you could manually unprotect A1 if you are unsure that the protect option that I showed you was not set.

    Or Unprotect and then Protect the ActiveSheet as Greg showed you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA for Insert Object >>Create from File>>Choose File. In Word Document
    By kt1993 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-08-2015, 03:43 PM
  2. Replies: 0
    Last Post: 06-19-2014, 02:09 PM
  3. [SOLVED] Variable User-form object name
    By sur4j in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-12-2014, 10:27 AM
  4. Replies: 4
    Last Post: 03-27-2013, 12:41 PM
  5. Collection of object control during Initializing user form
    By krish_kg in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2009, 05:39 AM
  6. [SOLVED] User form Object corruption
    By Datasort in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-19-2006, 03:20 PM
  7. How to insert OLE chart into a user form?
    By thesaint in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-06-2005, 05:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1