As I understood, Yongle's original code worked fine for you but you were looking for an adjustment, and I quote ....
one variation i am looking for. Anyway to have the file name to pre-populate when I save as?
The code as in my post #20 provides exactly what you are looking for! Some explanation to give you more insight.
The "Example" procedure shows how the "FileSaveAs" function is used. In the
sMyFile
variable you have to put the full path and filename to be used (initially, since users can change that name due to the dialog). For example, when you prefer to save the workbook as a workbook without macros, you give the filename (in the variabele
sMyFile
) the .XLSX extension. The
oWb
variable has to have the reference to the workbook you wish to save, in the example the active workbook but you may change that to "ThisWorkbook" (ie the workbook in which your code is running) or whatever workbook you like. Those two variables are passed on to the "FileSaveAs" function as arguments.
The "FileSaveAs" function determines the type of file as of its extension given by you (xlsx, xlsm, csv) and passes this on to the Save As Dialog. The Dialog will open in the folder based on the path of the filename given by you, the File Name input field is populated with the filename given by you and the Save As Type input field is populated according to the file type given by you (xlsx, xlsm, csv).
As mentioned before, users may navigate to another folder on disk, users may change the filename and may change the file type, after all that's where a dialog is for. Anyway, at the moment the user has dicided to press the save button the "FileSaveAs" function saves the workbook according to the users input in the Dialog, returns to its caller (the "Example" procedure) and provides a string with the full filename of the saved file (drive:\folder\subfolder\filename.ext). At the moment the user on the other hand has dicided to close the Dialog or to press the Cancel button, the "FileSaveAs" function puts a message on screen and returns to its caller (the "Example" procedure) with a string without characters ("").
I can't explain it better than this.