Macro Save File (Unique file name)

G

Guest

I currently have a code which I have listed below which will save a file when
the user selects the button. I have some users who will need to save two or
more files, which directs them to overwrite the file since currently, there
is no identifier in the file name. The indentifier that I would like to add
is on another spreadsheet in the same workbook. (Worksheet name:
Intro--Start Here; cell: G13)

Does anyone know how I can add this information to the filename so that each
file saved will have a unique name? Thanks for any suggestions.


Dim strPath As String
Dim strFileName As String

strPath = Application.DefaultFilePath & "\"
strFileName = "xxx"

ActiveWorkbook.SaveAs strPath & strFileName, FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
ActiveWindow.Close
Sheets("Intro--Start Here").Select
MsgBox ("xxx")

End Sub
 
G

Guest

Hi SJC,

Change strFileName = "xxx" to strFileName =
Range("G13").Value
Add this Sheets("Intro--Start Here").Select before
the line above.

This should do the trick! It basically select your intro sheet, and then
assigns a cell value (G13 in this case) to a variable which you then use save
the file.

Let me know if you have any more questions!

Cheers,

Kevin Lehrbass
(e-mail address removed)
www.spreadsheetsolutions4u.com
 
G

Guest

I have one more question if you have the time. I am also thinking I would
like to include 2 cells into the file name, but I am thinking I am not doing
it right. How would you suggest changing this path? The cell I want to add
is F@.

Range("C2").Select
strPath = Application.DefaultFilePath & "\"
strFileName = Range("C2").Value & "_xxx"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Create CSV 3
Save As Macro 2
Macro code error; machine dependent 4
VBA Save 3
Save file with todays date ref#11235 2
BeforeSave Event 5
BeforeSave 7
Hiding an Excel file using VBA 1

Top