Results 1 to 4 of 4

Thread: PDF create button in excel

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    16

    PDF create button in excel

    Hi,
    I have a button in my sheet which creates a PDF of the sheet and saves it to the users desktop. The name of the PDF is just the name of the excel file. I found that if the button is pushed twice without moving or renaming the PDF after the first push I get an error.

    How would I enable a user to choose the location and name for the PDF?

    The code:
    Code:
    Sub Button2336_Click()
    '
    ' Button2336_Click Macro
    '
    
    '
        ChDir "C:\Users\" & Environ("Username") & "\desktop\"
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=filesavename, _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
            :=False, OpenAfterPublish:=True
    End Sub
    Thanks for any help!

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Mar 2013
    Posts
    16

    Re: PDF create button in excel

    If I change;

    Filename:=filesavename, _

    to

    Filename:=InputBox("Enter file name"), _

    it lets you choose a file name and works the first time with no problems. The second time you push the button and select a different name it creates the PDF but displays a runtime error. Any ideas?

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: PDF create button in excel

    Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: PDF create button in excel

    what runtime error?
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width