+ Reply to Thread
Results 1 to 13 of 13

Use cell value in the file name when SaveAs

  1. #1
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Use cell value in the file name when SaveAs

    So if cell “A17” = October 2014
    and I am using:-
    Please Login or Register  to view this content.
    it gives me file path name:-
    Please Login or Register  to view this content.
    Two questions;
    1) how can I lose the double spacing between “# October”
    2) but what I would much prefer it to look like is,

    Please Login or Register  to view this content.
    I have experimented with “Trim” but just can’t get the syntax correct.

    Can any body help me with this?

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: Use cell value in the file name when SaveAs

    What's really in A17? Is it a real date?


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: Use cell value in the file name when SaveAs

    Thanks for your response TMS.

    Yes it is an actual date, just formatted mmmm yyyy

    julhs

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: Use cell value in the file name when SaveAs

    So, if you use .Text, you get what you see. Use Format with whatever formatting constant you require, for example, "mm yyyy". Can't test it right now but you should be able to get the brackets in ... which should answer both questions.


    Regards, TMS

  5. #5
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: Use cell value in the file name when SaveAs

    Made changes as suggested to this,

    Please Login or Register  to view this content.
    but getting Run-time error 438, Object doesn’t support this property or method.
    At present not tried including brackets around (yyyy)

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: Use cell value in the file name when SaveAs

    No, not quite.

    Please Login or Register  to view this content.

    Regards, TMS

  7. #7
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: Use cell value in the file name when SaveAs

    Getting

    Please Login or Register  to view this content.
    at “SaveAs2” now, at a loss to know why

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: Use cell value in the file name when SaveAs

    What is "SaveAs2"? I was assuming that it was a subroutine that you had created.

    I can't test this is as I don't have the workbook, the code, the data, the Word document.

    I can only help you fix the errors that you describe.

    The code I suggested works to set up the file name, as can be seen in the second example. Note that wdPath is an undefined variable and, as a result, is empty in the output string.

    Please Login or Register  to view this content.

    Regards, TMS

  9. #9
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: Use cell value in the file name when SaveAs

    It IS part of a working subroutine, that’s why I don’t understand why I am getting that error code now, after what I would class as only a subtle change to the FileName format.
    “SaveAs2” is a carryover of some old testing code, simply replacing it with “SaveAs” and my code still works.

    I will further digest what you have said and given me and see if I can figure things out, but I may have to come back to you if that’s ok?

    Many thanks
    julhs

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: Use cell value in the file name when SaveAs

    I may have to come back to you if that’s ok?
    Sure, but there's not much I can do without seeing the code in context.

    Is SaveAs2 in another module? Is it Private or Public or not stated? Where is the code that is calling it? In another module? In a worksheet module? In a Form module? If it exists, I can only assume the calling module cannot find it for some reason.

    Regards, TMS

  11. #11
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: Use cell value in the file name when SaveAs

    Found the problem, it really was one of the most basic of errors!!
    I had omitted the full stop preceding the “SaveAs2”

    This is where the offending “.SaveAs2” fitted in

    Please Login or Register  to view this content.
    Lesson learnt here is to keep things tidier when testing code, that way I may have spotted it sooner.

    TMS, thank you so much for all your help, but most of all your patience.

    julhs

  12. #12
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,492

    Re: Use cell value in the file name when SaveAs

    You're welcome. Thanks for the rep.


    And I have learned something too ... totally unaware that there was a SaveAs2 method for a Word document.

    Regards, TMS

  13. #13
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: Use cell value in the file name when SaveAs

    Credit for the SaveAs2 belongs to “macropod”

    regards, julhs

+ 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. Problem With Open File and Save File With Saveas and then close the File
    By John Vieren in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-27-2013, 12:53 AM
  2. [SOLVED] "saveas" with cell data as file name?
    By Eoluke in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-23-2013, 12:28 PM
  3. Macro to create a new file, saveas and close file
    By kaismum in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-21-2006, 09:34 AM
  4. [SOLVED] How can I make File->Save , File->SaveAs Menu disabled?
    By Zoo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-05-2006, 02:00 AM
  5. File SaveAs
    By FinChase in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-06-2006, 09:45 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