I have an Excel macro in which a user can input their name via an input box. I then want to take the name they enter and use it as part of the file path to which the workbook is saved.

For example. If user enters their name as John, I want the file to be saved to F:\Workbooks\John\. If the user enters their name as Fred, I want the file to be saved to F:\Workbooks\Fred\. And so on.

I have a variable set up for name as a string. How should I write the code though?

Activeworkbook.saveas filename:"F:\Workbook\VARIABLE" <----how should I write the variable?

Thank you for any help.



Activeworkbook.saveas filename:"F:\Workbook\" & variable &"\" & ActiveWorkbook.Name

or if you already have the name "F:\Workbook\" & variable &"\MyWorkbook.xls"

Check first if directory exists, if not - create it.

Seba Sama

Yep, creating the directories first solved my problem. I assumed the directories would automatically be created. Thank you so much for the help.


This question has already been answered. Start a new discussion instead.