Hi, I created a macro to open all excel spreadsheets in a particular folder. However when I run the code, I get an error "Visual Basic 400"
Please can you tell me why?

Sub smiley_face()
'macro to open all files within a folder and apply password
strPassword = InputBox("Please enter your password")
sPath = "S:\Circulation\R Winters\"
sDir = Dir$(sPath & "*.xls", vbNormal)
Do Until LenB(sDir) = 0
Application.AskToUpdateLinks = False
Workbooks.Open Filename:=sPath & sDir, Password:=strPassword
sDir = Dir$
End Sub

Open in new window

Who is Participating?
tajinderpalAuthor Commented:
Sorry that did not help
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Rory ArchibaldCommented:
Which line actually causes the error?
tajinderpalAuthor Commented:
It does not tell me what line the error is as. Just a pop up box appears with the error code 400
Kamaraj SubramanianApplication Support AnalystCommented:
Excel Error 400 is a "catch-all" error for something that Excel cannot resolve in de-coding Macro lines. It is applied to Application Define Errors or Object Define Errors.

Like you have a Variable defined as a type of number, but the data you are loading into it is a string or object. Bang-Error: 400.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.