Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy file

Status
Not open for further replies.

rmelnyck

Technical User
Sep 26, 2003
27
0
0
US
I am trying to check if a folder exists, if it doesn't I want to create it. This works no problem. The seocnd part is that I want to move a file from one folder to another but I keep getting a Run Time Error '5' Invalid procedure call or argument. It must be something stupid I am not seeing. Here is the code. Thanks!

Sub Create_Folder_If_NonExistant()

Dim fso
Dim c
Dim fol As String
fol = "C:\SystemServices"
sfol = "K:\GlobalDistribution\Combined Reports\ProgressReporter.dll"
dfol = "C:\SystemServices"

Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
fso.CopyFile sfo1, dfo1
Else
MsgBox fol & " already exists!"
fso.CopyFile sfo1, dfo1
End If

End Sub


 
You've called the Variables incorrectly.

dfol <> dfo1

use l instead of 1
 
Also, you need to have a \ after dfol = &quot;C:\SystemServices&quot; to make it dfol = &quot;C:\SystemServices\&quot; otherwise you'll get a &quot;Permission Denied&quot; error
 
Duh! Thanks! I needed a 2nd set of eyes to see that. I appreciate it.
 
No problem, i've done the same thing my self!

I found it by putting a break point in, and hovering the mouse over the variables, it said it was &quot;Null&quot; so i checked the code, and noticed it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top