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.

Noel

Recommended Answers

All 2 Replies

Try:

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.

Noel

Be a part of the DaniWeb community

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