copyfile method path not found

L

Lord Kelvan

I am getting this error and I take it is due to the destination path
does not exist is there a way to use this or another method to copy
the file and create the file path in its entirety.

Eg

SourceFile = c:/filex.doc
DestinationFile = C:/anexistingfolder/newfolder1/newfolder2/filex.doc

FSO.Copyfile SourceFile, DestinationFile
 
L

Lord Kelvan

nevermind i did some more searching and found this method

Sub MakeMultiDir(FullPath As String)
Dim V As Variant
Dim N As Long
Dim S As String
V = Split(FullPath, "\")

For N = LBound(V) To UBound(V)
S = S & V(N)
If Dir(S, vbDirectory) = vbNullString Then
MkDir S
End If
S = S & "\"
Next N
End Sub

and it seems to work fine
 
J

Jacob Skaria

Use the below procedure called Create Path to create folders....

Dim fso As Object
Sub Macro()
Dim strPath As String
Set fso = CreateObject("Scripting.FileSystemObject")
SourceFile = "c:\1.doc"
strPath = "C:\anexistingfolder\newfolder1\newfolder2\"
CreatePath strPath
DestinationFile = strPath & "filex.doc"
fso.Copyfile SourceFile, DestinationFile
End Sub


Sub CreatePath(strPath As String)
Dim varTemp, intTemp, strTemp
varTemp = Split(strPath, "\")
For intTemp = 0 To UBound(varTemp)
strTemp = strTemp & varTemp(intTemp) & "\"
If InStr(varTemp(intTemp), ":") = 0 And fso.FolderExists(strTemp) = False Then
fso.CreateFolder strTemp
End If
Next
End Sub

If this post helps click Yes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

copying Excel file without opening file 2
Copy Shortcut 2
Code Error 8
File Copy Error 1
FSO copy file returns permission denied 5
Check For File 4
Moving Files 4
Copy, Paste, Hide 4

Top