+ Reply to Thread
Results 1 to 15 of 15

Save active workbook Filename glitch

  1. #1
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    310

    Save active workbook Filename glitch

    Hi again!

    My code copies a worksheet into a new workbook, names the sheet, deletes the "Sheet1" that comes with the new workbook and is then meant to save the workbook in a folder that has previously been checked as being real, under a filename made up form data in the worksheet.

    All is good until it comes to the filename the sheet is saved as. If I step through the code the line
    Please Login or Register  to view this content.
    shows up with the full path and file name. The Message Box also comes up with the correct information. HOWEVER, The filename the the new workbook saves under is "FALSE.xlsm"

    Here's the relevant bit of code
    Please Login or Register  to view this content.
    Any ideas why this doesn't work please??

    Thanks

    Frankie

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

    Re: Save active workbook Filename glitch

    Hi Frankie,

    maybe change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Besides: the relevant part would be where the variables get their values, and I would think about renaming most of the variables you use as they are part of the VBA Keywords.

    Ciao,
    Holger
    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 Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Save active workbook Filename glitch

    Your code does not specify what value of Filename is...
    Should the red snippet not be CName
    Please Login or Register  to view this content.
    Perhaps upload a sample file and explain in detail what it is you are trying to achieve...
    Last edited by Sintek; 05-26-2021 at 05:10 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

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

    Re: Save active workbook Filename glitch

    Hi Frankie,

    first of all I wonder why you would need to delete sheets from a workbook you copied a worksheet to. It´s only necessary if you add a workbook first and then copy opver the sheeet. You could avoid delting sheets by just using
    Please Login or Register  to view this content.
    which would copy the sheet over into a newly created workbook with no other sheets.

    In your snuplet you use wb as well as ActiveWorkbook. I suppose it´s the same workbook rhroughout and you should be consoistent in the code to use for a certain workbook.

    Last the question why the code line returns False for the workbook name. You compare the filename to another string which also contains the filename plus more information. So no match would ever be found. And if a match is Found the filename for teh workbook would be True...

    The proper syntax for the SaveAs Command would be
    Please Login or Register  to view this content.
    and it should be used as
    Please Login or Register  to view this content.
    HTH,
    Holger

  5. #5
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    310

    Re: Save active workbook Filename glitch

    Hi sintec

    Thanks for the input.

    CName is the name of the sheet while Filename is the name for the workbook being saved. Company Name and Invoice number for the sheet and "Invoice For" Company Name and Invoice Number along with file extension for the filename.
    (Discussed with the end user who wants it this way!!)

    Cheers

    Frankie

  6. #6
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    310

    Re: Save active workbook Filename glitch

    Hi HaHoBe

    Thanks for your input too.
    I loaded your code and changed the Const cstrPATH, Folder, SubFolder to the names I want but when it comes to the file name
    Please Login or Register  to view this content.
    it throws up "constant expression required" and highlights the ".Value". If I remove .Value it just highlights the ".Range"

    The FileName is variable dependent of info in cells C3 and J9 so how do I write this for the Const cstrFileName please?

    Frankie

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

    Re: Save active workbook Filename glitch

    Hi Frankie,

    imy sample was for demonstration only, so I used Constants. If you rely on variables like information from ranges you should use
    Please Login or Register  to view this content.
    and change the variable in the line for saving as well.

    Ciao,
    Holger
    Last edited by HaHoBe; 05-27-2021 at 01:38 AM.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,958

    Re: Save active workbook Filename glitch

    Frankie...I suggest your sample file upload and explain your end result requirement...You know that this has always proven to render results...
    i.e. I want this file to be saved in this SubFolder of this Folder named from this range etc etc etc ...

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,009

    Re: Save active workbook Filename glitch

    Your syntax is wrong - you're missing a colon:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

  10. #10
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    310

    Re: Save active workbook Filename glitch

    OK. Here's a sanatised version of the workbook.

    Everything appears to work aside from saving the Invoice under the company name and invoice number in the folder "REC" SubFolder "REC Invoices".

    Thanks for the assistance

    Frankie
    Attached Files Attached Files

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

    Re: Save active workbook Filename glitch

    Hi FRankie,

    AFAIK the character # should be avoided for filenames.

    I would have expected most of the procedures in a standard module as by now the codes are copied to the new workbook due to the fact that they are placed behind the sheet.

    Code for TrackInvoice:
    Please Login or Register  to view this content.
    Code for SaveInvoice where I changed # to No.:
    Please Login or Register  to view this content.
    Ciao,
    Holger

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

    Re: Save active workbook Filename glitch

    Hi Frankie,

    if the codes aren´t needed in the copy you could consider to save as a normal workbook with the extension xlsx (FiuleFormat woul be 51) which would leave you with a macro free copy.

    As there are problems reported with that way you should take the road with a standard moule for the codes.

    Ciao,
    Holger
    Last edited by HaHoBe; 05-28-2021 at 03:44 AM.

  13. #13
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    310

    Re: Save active workbook Filename glitch

    Good Stuff HaHoBe!! Vielen Dank!

    Frankie

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

    Re: Save active workbook Filename glitch

    Hi Frankie,

    thanks for the fededback. I attach a copy of your workbook where all procedures have been put into modules (where possible) and those begind the sheet made to only work in the workbook due to comparing the workbook name to constants.

    Maybe have a look at it.

    Ciao,
    Holger
    Attached Files Attached Files

  15. #15
    Forum Contributor
    Join Date
    09-22-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 2019
    Posts
    310

    Re: Save active workbook Filename glitch

    Thanks HaHoBe. (I was going to do this but got carried away with building the workbook! :-))

+ 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. Replies: 7
    Last Post: 05-28-2020, 09:45 AM
  2. Save active sheet on path and with filename from cell
    By MetteGaga in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-02-2016, 07:33 PM
  3. [SOLVED] VBA Script to save single tab as new workbook using tab name for filename
    By Webbers in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-17-2015, 08:25 AM
  4. [SOLVED] VBA to Open File (filename contains current date) & copy Sheet to active workbook
    By jlstidham in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-12-2013, 10:50 PM
  5. Save as workbook with date and time in filename
    By Undeveloped in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2013, 05:08 PM
  6. [SOLVED] Save Active Filename
    By timbo1957 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-13-2011, 12:43 PM
  7. macro to save sheet from workbook. Specified location and filename
    By rain4u in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-14-2011, 11:47 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