+ Reply to Thread
Results 1 to 10 of 10

Save File As - Cancelling

  1. #1
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    179

    Save File As - Cancelling

    Gurus,

    I have to code below that brings up the "Save As" box to save a file which is in AP3.

    It works well, except, if the user selects cancel, instead of save, the file is saved as False. What I am looking for is the code that exits the macro (and doesn't save the file) when Cancel is selected. Any ideas?

    TIA,
    Tim



    Please Login or Register  to view this content.
    Last edited by TimlmiT; 05-16-2014 at 12:36 PM.

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Save File As - Cancelling

    Hi, TimlmiT,

    maybe try it like this:
    Please Login or Register  to view this content.
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    179

    Re: Save File As - Cancelling

    HaHoBe,

    Works great! I am not sure if I understand why or what makes the difference between it being a strPath and varPath, nevertheless it works.

    Thank you!
    TimlmiT (novice)

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Save File As - Cancelling

    Hi, Tim,

    strPath was dimensioned as String which may only take a string (not so surprising). If the user cancelled a Boolean is raised which canīt be covered by a String. A Variant can take any type (as well String as Boolean) so declaring the variable as Variant will work.

    HTH,
    Holger

  5. #5
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    179

    Re: Save File As - Cancelling

    Thank you for your explanation.

  6. #6
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    179

    Re: Save File As - Cancelling

    Holger,

    Can you help me with this one? The code is slightly different when saving it as an .xlsm file. I get the same "false.xlsm" file if the user selects cancel.

    Please Login or Register  to view this content.
    TIA,
    Tim

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Save File As - Cancelling

    Hi, Tim,

    Please Login or Register  to view this content.
    I donīt think you would need to use a variable for the suggested name but could use the range directly.

    Ciao,
    Holger

  8. #8
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    179

    Re: Save File As - Cancelling

    Holger,

    Thank you for the help.

    However, in the picture, you can see that the file name (Green) and value (Blue) are the same. But when SAVE is selected on the menu, the result (Red) has and additional "." on the end of the file name.


    excel.jpg

    Any clues of why this is happening?
    Thanks,
    Tim

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Save File As - Cancelling

    Hi, Tim,

    my last code is for *.xlsm so you would need to review the code to ExportAsFixedFormat and see if you would need to either cut off one more character from the filename or add only pdf without a dot. I canīt find any reason ad hoc - sorry.

    Ciao,
    Holger

  10. #10
    Forum Contributor
    Join Date
    06-21-2013
    Location
    Chicago, IL
    MS-Off Ver
    Excel 2010
    Posts
    179

    Re: Save File As - Cancelling

    Holger,

    Below is the code for both the Save_As and Save_PDF. I played around with the Save_PDF and found that in order for it not to add the period to the end of the file name, I had make the filename = to a string and not a variable. Not sure why, but it works great now.

    Thanks for your help.
    Tim

    Please Login or Register  to view this content.

+ 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 needed to open "File Save As" and change save file type
    By blainerhett in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-28-2014, 02:40 PM
  2. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  3. Save as macro that specifies file type, file location and takes file name from three cells
    By ExcelFailure in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 06-13-2013, 10:09 PM
  4. VBA Cancelling the Open File Dialogue
    By Mase123y in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-20-2009, 01:37 PM
  5. Replies: 0
    Last Post: 03-09-2005, 06:06 PM

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