Gitty
Gitty

Reputation: 166

Receive Run-time Error 58 File Already Exists When It Doesn't

I keep on receiving

"Run-time Error 58 File Already Exists"

when trying to run the below code. I've double and triple checked and the file definitely doesn't exist.

I run a different Macro first that gets me the location of the folder I want to create this new folder in. The location is displayed in ActiveWorkbook.Sheets(1).Range("A1"). Master File is the name of the new folder I want to create.

Sub CreateFolder

Dim Bname As String
Bname = ActiveWorkbook.Sheets(1).Range("A1").Text & "\Master File"
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateFolder "Bname"

End Sub

I've also tried the following:

Sub CreateFolder

Dim Bname As String
Bname = ActiveWorkbook.Sheets(1).Range("A1").Text & "\Master File"
MkDir "Bname"

End Sub

Upvotes: 1

Views: 884

Answers (1)

basic
basic

Reputation: 11968

You create folder 'Bname', not '..\Master File'. Do not use quotation marks around the variable.

fso.CreateFolder Bname

Upvotes: 2

Related Questions