+ Reply to Thread
Results 1 to 5 of 5

Copy cell data into file name in save as file name

  1. #1
    Registered User
    Join Date
    06-28-2016
    Location
    Fargo, ND USA
    MS-Off Ver
    10
    Posts
    32

    Copy cell data into file name in save as file name

    I have a read only file that I want users to be able to save the workbook in the same folder as the original read only file which I will not know ahead of time - up to the user. I have set up a "Save as " button on the worksheet using Application.GetSaveAsFilename which works fine. When the "Save As" window pops up, I would like "File Name" box populated with data from cells in the worksheet as a "suggested name" that will make sense when we pull it up later - (it is an price and order sheet). The cell names are "H7","H4" and "H14", If any of these are empty, it would be nice to be able to put up a text message to tell them to populate it correctly.

    Thanks in advance
    Last edited by tomneedshelp; 07-27-2016 at 11:10 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Copy cell data into file name in save as file name

    Hello tomneedshelp,

    To add a document name to the SaveAs dialog box, you have to call it from the Excel Built-in Dialogs. The macro below does that. Since this method only returns True or False, the file name and path are retrieved from the Recent Files list. The last saved file will always be at the top of the list.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 07-26-2016 at 09:25 PM.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    06-28-2016
    Location
    Fargo, ND USA
    MS-Off Ver
    10
    Posts
    32

    Re: Copy cell data into file name in save as file name

    Keith, Thanks for the help - it saves the file as you said, but I am not getting the message box to come up as expected when a cell is empty. I set up a simple Message Box Button to try out the message box function and that comes up every time, but when I put in this code, it doesn't seem to come up when the target cell is empty.

    Did I screw something up?

    Sub SaveFile()

    If IsEmpty(Trim(Range("H7"))) Then
    MsgBox "The file name is incomplete. Please Fill In Dealer Name.", vbExclamation
    End If
    End Sub
    Last edited by tomneedshelp; 07-27-2016 at 10:46 AM.

  4. #4
    Registered User
    Join Date
    06-28-2016
    Location
    Fargo, ND USA
    MS-Off Ver
    10
    Posts
    32

    Re: Copy cell data into file name in save as file name

    Got it,

    For some reason (way over my head) I had to eliminate the Trim statement and then it worked fine.

    Thanks for your help

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Copy cell data into file name in save as file name

    Hello tomsneedshelp,

    Nice work! That was my fault. IsEmpty requires a Variant argument, in this case the cell. Trim removes the leading and trailing spaces from the cell value and returns a string value.

+ 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 to copy data to a template file then save it as a new file.
    By Efjoker in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-20-2019, 12:10 PM
  2. Want to open file, copy filtered data to new workbook and at save as new file
    By satishdu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-25-2014, 12:39 PM
  3. Copy, edit and save workbook to same location as source data file, not macro file.
    By Jasonhouse in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2014, 09:01 AM
  4. Replies: 0
    Last Post: 03-11-2014, 08:18 AM
  5. Replies: 1
    Last Post: 09-05-2013, 02:39 PM
  6. Replies: 1
    Last Post: 08-16-2013, 04:23 AM
  7. [SOLVED] Copy row from active file to another formated excell file and save as one cell value
    By snsuvarna in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-16-2013, 04:18 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