File Naming conventions for VBA

0

Hi, I have created a macro that steps through folders and opens each individual workbook runs a standard macro in that workbook closes the files and moves onto the next file until all have been done.

I have used Application.Run (File.Name & "!UpdatePeriod") to call and run the macro, where UpdatePeriod is the macro name in each workbook. The issue I have is that if the filename may contain spaces or characters like (&-) and then the macro stops saying that it cannot access the macro. At the end of the macro I am resaving the file with a different name including the current period. Are there any guidelines or rules that I should be following in terms of naming conventions so that opening the file and running the macro is not an issue?

Many thanks in advance.

Answer
Discuss

Answers

0

If there are spaces in the file name it must be surrounded by single quotes. For example,

Application.Run ("'" & File.Name & "'!UpdatePeriod"

Excel will ignore the quotes if there are no spaces. Therefore they should be standard syntax for this type of code.

Discuss

Answer the Question

You must create an account to use the forum. Create an Account or Login