+ Reply to Thread
Results 1 to 8 of 8

Help to add code to save file as a specific name

  1. #1
    Forum Contributor
    Join Date
    03-30-2015
    Location
    Northampton
    MS-Off Ver
    2010
    Posts
    275

    Help to add code to save file as a specific name

    Hi all

    i have put this on another forum but as yet i have not had a response. ive added a picture to demonstrate what it is that i would like to achieve.

    i would like to add come code in to the following code.

    Please Login or Register  to view this content.
    i wish to combine the invoice number (example "12", located in cell N14) and add it to the client Id (example "oup102") so the file name will look like this "oup10212"
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Help to add code to save file as a specific name

    Hi,

    At the moment you're prompting for the file name with the GetSaveAsFileName instruction.

    If you want to read the filename from the Excel App then comment out the GetSaveAs.... and use instead of

    Filename:=Opendialog, _

    this

    Filename:=Sheet2.Range("J4")&Sheet2.Range("N14")
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    03-30-2015
    Location
    Northampton
    MS-Off Ver
    2010
    Posts
    275

    Re: Help to add code to save file as a specific name

    Quote Originally Posted by Richard Buttrey View Post
    Hi,

    At the moment you're prompting for the file name with the GetSaveAsFileName instruction.

    If you want to read the filename from the Excel App then comment out the GetSaveAs.... and use instead of

    Filename:=Opendialog, _

    this

    Filename:=Sheet2.Range("J4")&Sheet2.Range("N14")
    i tried that but did not work, here is the amended code if i read it right

    Please Login or Register  to view this content.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Help to add code to save file as a specific name

    Delete the

    Filename = Sheet2.Range("J4") & Sheet2.Range("N14")("", filefilter:="PDF Files (*.pdf), *.pdf", _
    Title:="Your Invoice")

    and instead include the Title:= bit further down in the Filename:= section

  5. #5
    Forum Contributor
    Join Date
    03-30-2015
    Location
    Northampton
    MS-Off Ver
    2010
    Posts
    275

    Re: Help to add code to save file as a specific name

    Quote Originally Posted by Richard Buttrey View Post
    Delete the

    Filename = Sheet2.Range("J4") & Sheet2.Range("N14")("", filefilter:="PDF Files (*.pdf), *.pdf", _
    Title:="Your Invoice")

    and instead include the Title:= bit further down in the Filename:= section
    all the following turns red

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    03-30-2015
    Location
    Northampton
    MS-Off Ver
    2010
    Posts
    275

    Re: Help to add code to save file as a specific name

    error message

    filefilter argument not found

  7. #7
    Forum Contributor
    Join Date
    03-30-2015
    Location
    Northampton
    MS-Off Ver
    2010
    Posts
    275

    Re: Help to add code to save file as a specific name

    ok here is my code and works now

    Please Login or Register  to view this content.
    Many thanks for your help
    Last edited by Learning ExL; 05-15-2016 at 02:36 PM.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Help to add code to save file as a specific name

    It will because the ...("N14")("".... bit is meaningless which is why I said to delete this wrapped round line. I didn't add but since you're not using the Opendialog variable neither do you need this whole section
    Please Login or Register  to view this content.
    and lower down use
    Please Login or Register  to view this content.
    Incidentally it's good practice to have an Option Explicit as the first line above any procedure and declare variables with a Dim statement. Without the Option Explicit variables like the 'opendialog' you were using (but not now) get declared automatically. This means that should you accidentally misspell the variable later when you give it a value, e.g suppose you wrote 'opendilog' = something or other, the misspelled opendilog is treated as a new variable and you'll be scratching your head wondering why, when later you use the correct name 'opendialog' thinking you've applied a value to it, things aren't working as you expect.

+ 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: 3
    Last Post: 04-04-2016, 03:50 AM
  2. [SOLVED] Save selected print area as a pdf file using the text from a specific cells as the file na
    By A440 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-17-2015, 04:14 PM
  3. [SOLVED] Save as xlsm file with specific name & specific folder
    By namialus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-07-2015, 03:32 AM
  4. [SOLVED] VBA code to save as file with specific file name
    By wolfm in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 12-10-2014, 10:45 AM
  5. [SOLVED] Macro to manually choose PDF file and save it to a specific location with specific name
    By tnuis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-18-2014, 07:47 AM
  6. Replies: 0
    Last Post: 07-11-2013, 02:08 AM
  7. [SOLVED] macro to save file to specific folder with file name from cell reference
    By mezza89 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2013, 11:32 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