+ Reply to Thread
Results 1 to 19 of 19

Macro that saves worksheet as a PDF with specified cell value

  1. #1
    Registered User
    Join Date
    08-21-2013
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Macro that saves worksheet as a PDF with specified cell value

    Hi All,

    I am new to VBA, and was hoping someone could help me with one of my macros. I am trying to make a macro that will save a worksheet as a PDF with a specific name and date (which will change). In addition, this file will be saved as a pdf often with new information each time, so the macro needs to capture the name and date changes to distinguish the different pdf copies. Here is what I have so far:

    Please Login or Register  to view this content.
    In Cell A6 I have the following:

    ="C:\Users\Connor\Documents\For Work\"&TEXT($E$8,"Text")&"_"&TEXT($G$3,"mmm-dd-YYYY")&".pdf"

    Where E8 is the cell containing the name (that changes) and G3 is a cell with the date on the excel form.
    The line shows up like I expected:

    C:\Users\Connor\Documents\For Work\Name_Sep-01-2013.pdf

    However, when I go to run the macro, I keep getting an error type 13 mismatch, and I can't figure out where I went wrong.

    Does anyone know what I'm doing wrong? Thanks in advance!!
    Last edited by JBeaucaire; 08-28-2013 at 07:08 PM. Reason: Added CODE tags, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thanks.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro that saves worksheet as a PDF with specified cell value

    Test

    Please Login or Register  to view this content.
    instead

    Alf

  3. #3
    Registered User
    Join Date
    08-21-2013
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro that saves worksheet as a PDF with specified cell value

    Thank you Alf, that got rid of that error. However, now I am getting a "run-time error 1004" saying that the doc cant be saved. Any ideas?

    Thanks for your help!

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro that saves worksheet as a PDF with specified cell value

    Try changing

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    If that does not help perhaps you could upload a mockup file I could test.

    Alf

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi connor12

    Try changing this
    Please Login or Register  to view this content.
    to this
    Please Login or Register  to view this content.
    As Alf noted, you also need to Dim s as a String.

    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Registered User
    Join Date
    08-21-2013
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi John,

    Unfortunately changing value to text results in the same error. Could it be something to do with the default macro settings in excel? I can't seem to figure out what it is that I am doing wrong.

    Thanks for your help,

    Connor

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi connor12

    I don't know Connor, I simulated your stuff and using this Code
    Please Login or Register  to view this content.
    Attached you'll see my Output.

    Is there some Code you've not shared?
    Attached Files Attached Files

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi connor12

    A thought just struck me...is THIS on the ActiveSheet...of not you'll need to fully qualify it.
    Please Login or Register  to view this content.
    Last edited by jaslake; 08-29-2013 at 06:28 PM.

  9. #9
    Registered User
    Join Date
    08-21-2013
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro that saves worksheet as a PDF with specified cell value

    What I have posted is the only code that I used, that's why I'm wondering if it is something to do with my settings somewhere in excel?

    Everything I am doing with this macro (button, cell reference, worksheet I want copied), is all on the same worksheet, so it's not a problem of activating the worksheet. Also, if I set 's' to a blank cell on the same worksheet (for mine I used E5 as an example), then the macro works, and saves it as "0.pdf" in the same folder location as where my excel form is found (which is the same location I am trying to get the macro to save the PDF version of the sheet to)

    I realize this reply is a bit wordy, so please let me know if I am being unclear anywhere.

    Thank you,

    Connor

  10. #10
    Registered User
    Join Date
    08-21-2013
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro that saves worksheet as a PDF with specified cell value

    Sorry, my mistake, if I set 's' to a blank cell "E5", it saves it as the same name as the excel workbook, just in a PDF format.

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi Conner

    As I've said, I can simulate your environment and the Code does as desired. If you'd like me to try to troubleshoot it more I'll need to see your File.

  12. #12
    Registered User
    Join Date
    08-21-2013
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi Jaslake,

    sorry for the late reply, I have been caught up at work. Here is the file. I made some changes as to the name of the folder where the PDF macro should save it, and I changed the code accordingly. Still not sure why it isn't working.

    Thank you,

    Connor
    Attached Files Attached Files

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi Conner

    This Code in the attached works for me in Excel 2007 and 2010...don't honestly know what the issue could be.

    There's no settings I'm aware of that would affect this...what Version of Excel are you running...
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    08-21-2013
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro that saves worksheet as a PDF with specified cell value

    I'm using excel 2010, still doesn't work. Thank you for your help though

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi Conner

    I'll try to get some Experts to look at this...perhaps they can shed some light on the issue...
    Attached Files Attached Files

  16. #16
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Macro that saves worksheet as a PDF with specified cell value

    Does the directory exist?

    Is there a .log file in the directory where the pdf was supposed to appear?
    Entia non sunt multiplicanda sine necessitate

  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro that saves worksheet as a PDF with specified cell value

    @shg

    I'll wait...an obvious question...built the OP's Tree...worked for me...

  18. #18
    Registered User
    Join Date
    08-21-2013
    Location
    Kelowna, Canada
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: Macro that saves worksheet as a PDF with specified cell value

    The PDF file was supposed to appear in the folder titled "For Jag"

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro that saves worksheet as a PDF with specified cell value

    Hi Conner

    Are you getting an Error Message?

+ 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 which saves data from temp worksheet to customers worksheet?
    By lala121 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-17-2013, 09:12 AM
  2. Replies: 1
    Last Post: 07-12-2012, 11:00 PM
  3. Can you create a macro that creates a macro and saves to a worksheet?
    By rob.parson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2012, 07:49 PM
  4. VBA Macro that converts and saves the worksheet into a PDF & customizing the filename
    By jonvanwyk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2011, 03:17 PM
  5. macro which saves the cell values of every column of every worksheet to one txt list?
    By forhekset in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-11-2011, 06:37 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