+ Reply to Thread
Results 1 to 10 of 10

Saving File as pdf with Macro

  1. #1
    Registered User
    Join Date
    06-03-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    9

    Saving File as pdf with Macro

    Hi All,

    Simple question (I hope). Just want to save a worksheet as pdf with the click of a button. The file should have date (cell F1), invoice number (cell F7) and Customer Name (cell B7).

    Hoping someone can help me with this asap.

    Thanks.

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Saving File as pdf with Macro

    I know its three clicks, but whats wrong with File tab->Save & Send->CreatePDF?

    Are the three cells you mention in your post already populated? Intentionally left blank to receive the values you specified?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,869

    Re: Saving File as pdf with Macro

    Something like:

    Please Login or Register  to view this content.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    06-03-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Saving File as pdf with Macro

    I'm still having trouble. Where exactly in the code do I put what folder I want to save the pdf file?

    ie. I'm using a mac and the location of the files should be saved here: /Users/domgee/Documents/Invoices

    Sorry I am not too savvy when it comes to this. Thanks for all your help

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,869

    Re: Saving File as pdf with Macro

    In the example, I have set the path (sReportPath) to be the same as the Workbook's path.

    In your case, it looks as though you'd change:

    Please Login or Register  to view this content.

    to:

    Please Login or Register  to view this content.

    Regards, TMS

  6. #6
    Registered User
    Join Date
    06-03-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Saving File as pdf with Macro

    Thanks for the reply but nothing happens when I click the button. This is my exact coding:

    Sub SaveInvoice()
    sReportPath = "/Users/domgee/Documents/Invoices"
    sReportName = Range("F1").Value & " " & Range("F7").Value & " " & Range("B7").Value
    On Error Resume Next
    ActiveSheet.ExportAsFixedFormat _
    Type:=xlTypePDF, _
    Filename:= _
    sReportPath & _
    Application.PathSeparator & _
    sReportName & _
    ".pdf", _
    Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, _
    IgnorePrintAreas:=False, _
    OpenAfterPublish:=False
    On Error GoTo 0
    End Sub

    Is something missing?

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,869

    Re: Saving File as pdf with Macro

    Have you assigned the macro to the button? Have you enabled macros? Can you step through the code using F8?

    Suggest that you post a sample workbook.

    Regards, TMS

  8. #8
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Saving File as pdf with Macro

    I put this in a project recently, and this is all that was needed. But, I wanted the same name. You could come up with a different file name for the variable 'fName'. I wanted the same name with a different extension, in the same directory.

    .fullname give you the workbook path and file name, if you want another directory to be used just write it in place of my formula on the right hand side of the equal sign. Also, using values from the sheet in the file name can cause something like this to fail if those cells contain non-valid file name characters.


    Please Login or Register  to view this content.
    Last edited by GeneralDisarray; 07-24-2013 at 02:36 PM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  9. #9
    Registered User
    Join Date
    06-03-2013
    Location
    Toronto
    MS-Off Ver
    Excel 2007
    Posts
    9

    Re: Saving File as pdf with Macro

    I will try your suggestion but in the meantime here is the uploaded worksheet. I have assigned the Macro and Macros are enabled.
    Attached Files Attached Files

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,869

    Re: Saving File as pdf with Macro

    Three problems. 1) The workbook does not have any code in it and, consequently, 2) the button does not have a macro assigned to it. And 3) the cells that are used to build the file name are empty so the code cannot save a file with just a couple of spaces as the file name ... difficult to find, I guess.

    This code works for me. It is, however, set up for testing so you'll need to adjust it.

    Please Login or Register  to view this content.

    See the attached amended workbook.

    Regards, TMS
    Attached Files Attached Files

+ 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. Macro for selecting & saving a MP4 file from Excel file
    By xlman in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2010, 03:31 AM
  2. Saving File with a macro
    By Foxcan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-13-2009, 02:25 PM
  3. Saving a File with specific file name using Macro
    By LstarS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-19-2009, 06:13 AM
  4. saving file in a macro
    By jartzh in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-08-2008, 04:20 PM
  5. File Saving macro ?!?!
    By hemants in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-22-2006, 07:20 PM

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