+ Reply to Thread
Results 1 to 10 of 10

VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

  1. #1
    Registered User
    Join Date
    02-04-2021
    Location
    Walsall, England
    MS-Off Ver
    Office 365
    Posts
    17

    VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    Hi,

    My knowledge of VBA is patchy at best but i have found my around the below but experiencing issues!

    I have a PO log spreadsheet that when opened on the click of a button will generate a new PO number. When I run the autosave it will save the file as a PDF into the exact designated location however, if the file name (PO Number) already exists it simply overwrites the file with the new version. Is there anyway i can ad a prompt "PO already in use" should the file already exist or continue should it not exist?? . i.e. I don't want to override at all!

    Any help would be really appreciated.
    Many thanks

    Here's my current coding;

    Sub Autosave()
    Dim vDir

    pdfname = ActiveSheet.Range("Q2")
    vDir = "\\cdhnas\cdh\Reports\Internal PO Log\PO pdf's\"
    fileSaveName = vDir & pdfname

    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fileSaveName, _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

    MsgBox "PDF File Saved (Reports\Internal PO Log\PO pdf's)"
    End Sub

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    Try this code

    Please Login or Register  to view this content.
    Note: Welcome to the Forum, please use code tags around the code you posted(edit your posts, highlight your code, and press the # in bar above the edit box)

  3. #3
    Registered User
    Join Date
    02-04-2021
    Location
    Walsall, England
    MS-Off Ver
    Office 365
    Posts
    17

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    Thanks for the quick response (and for the advice, i'm new!!).....however it didn't work!!

    I tried switching the code round as below; it kind of made more sense to me but in coding world probably the opposite!

    Please Login or Register  to view this content.
    But i get the opposite now, i.e. "The file exists"
    Last edited by alex900_6; 02-04-2021 at 04:30 PM.

  4. #4
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    Try the code this way

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-04-2021
    Location
    Walsall, England
    MS-Off Ver
    Office 365
    Posts
    17

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    Still no joy!!!.......just keeps over writing the previous save!!

    Sorry to be a pain

  6. #6
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    Another approach, also checking for pdf extension

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    02-04-2021
    Location
    Walsall, England
    MS-Off Ver
    Office 365
    Posts
    17

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    YES!!!!......perfect, it's worked :-)

    Many thanks for your help, Excel is so frustrating but so satisfying at the same time!!

    Thanks again

  8. #8
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    If that takes care of your original question, please select*Thread Tools*from the menu link above and mark this thread as SOLVED.

    Also, as a relatively new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  9. #9
    Registered User
    Join Date
    02-04-2021
    Location
    Walsall, England
    MS-Off Ver
    Office 365
    Posts
    17

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    Understood....just done that so again thanks, i'll now close the thread as solved.

    As you say, these are only things i'll pick up as i get more experienced with the forum.

    Thanks again

  10. #10
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: VBA for Autosaving a file to .pdf BUT not allowing overwrite if file already exists

    Your welcome,

+ 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] Autosaving file issue
    By Smally in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-04-2017, 06:03 AM
  2. [SOLVED] VBA to Promt if PDF exists and to overwrite - Close Existing File first
    By bdouglas1011 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2014, 03:09 AM
  3. Replies: 2
    Last Post: 01-28-2014, 08:45 AM
  4. Replies: 2
    Last Post: 01-16-2013, 03:10 PM
  5. [SOLVED] Stop overwrite of file if it already exists, no popup wanted
    By LoneWolf3574 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2012, 07:24 AM
  6. Save as macro allowing user to overwrite old file
    By jsantos in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-12-2011, 08:41 PM
  7. [SOLVED] Problems Autosaving an excel file/sheet as Text
    By MaxFrance in forum Excel General
    Replies: 0
    Last Post: 03-25-2005, 06:07 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