+ Reply to Thread
Results 1 to 5 of 5

Save PDF to same file as the Excel workbook

  1. #1
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Save PDF to same file as the Excel workbook

    I have a macro that print certain sheet to PDF once a button is pressed, It works perfectly well. However, the PDF save in D drive under the name "file" I would like this to save in the same folder/file as the excel workbook and the name to be the same as the excel workbook. Could someone please look at the script and suggest/make these changes. Much appreciated.

    Please Login or Register  to view this content.
    Last edited by Kevin Rush; 09-12-2021 at 10:53 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-24-2020
    Location
    Thailand
    MS-Off Ver
    Office 2016
    Posts
    897

    Re: Save PDF to same file as the Excel workbook

    Hi there,



    At the beginning add, after the third line stating with 'DIM': (declare variable, then assign the current file path (current workbook) as the file path.

    Dim myPath As Variant
    myPath = ThisWorkbook.Path


    Change:
    sNewFilePath = "D:\file.pdf" to: sNewFilePath = myPath & "\file.pdf"

    That should do the trick.
    If your Question is answered; please mark it SOLVED. If you are happy with a member's solution, say 'Thanks' and click the 'Star' to Add Reputation.

  3. #3
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Save PDF to same file as the Excel workbook

    Brilliant, that worked perfectly. Thank you!! The PDF save under the name file, is the away to save it as the same name as the workbook?

  4. #4
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Save PDF to same file as the Excel workbook

    Not tested due to lack of sample file.

    Please Login or Register  to view this content.
    Last edited by Vraag en antwoord; 09-12-2021 at 10:29 AM.
    Messages have been translated from Dutch to English by means of google translate.

  5. #5
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Save PDF to same file as the Excel workbook

    Thank you, I used the end of the script and it worked.

+ 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. [SOLVED] VBA code to save excel file to PDF under the current name of workbook.
    By reimar_rem in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-03-2018, 04:10 AM
  2. Replies: 3
    Last Post: 03-12-2018, 11:51 AM
  3. [SOLVED] Save each sheet in workbook to different excel file
    By Jarvin24 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-29-2016, 11:25 AM
  4. [SOLVED] Save the split the workbook file type as Excel Binary Workbook From Run Macro
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-25-2013, 05:09 AM
  5. Replies: 5
    Last Post: 03-21-2013, 07:34 AM
  6. save an excel workbook / file
    By oritny in forum Excel General
    Replies: 1
    Last Post: 11-03-2006, 03:31 AM
  7. [SOLVED] User cannot save excel file in workbook
    By Justin@Martin in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-16-2005, 09:06 AM

Tags for this Thread

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