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.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.