I have played around a bit more and can get this to work when I "note" out the SaveAs code, press my button, go back into the code and remove the ' from the SaveAs code and then press the button again.
Looking around on here and other sites, it is obviosuly giving the error as it can't find the folder I am asking the code to create and the save the file into this new folder.
Is there a way around this?
Kieran
ActiveWorkbook.SaveAs Filename:=Name, _
FileFormat:=50, CreateBackup:=False
Option Explicit
Sub Copy_Folder()
'This example copy all files and subfolders from FromPath to ToPath.
'Note: If ToPath already exist it will overwrite existing files in this folder
'if ToPath not exist it will be made for you.
Dim FSO As Object
Dim FromPath As String
Dim ToPath As String
FromPath = "K:\APPS\Standard Document Files\Contracts\New Contract Folder" '<< Change
ToPath = "K:\APPS\CONTRACT\Test\" & Range("A3") & " " & Range("A5") '<< Change
If Right(FromPath, 1) = "\" Then
FromPath = Left(FromPath, Len(FromPath) - 1)
End If
If Right(ToPath, 1) = "\" Then
ToPath = Left(ToPath, Len(ToPath) - 1)
End If
Set FSO = CreateObject("scripting.filesystemobject")
If FSO.FolderExists(FromPath) = False Then
MsgBox FromPath & " doesn't exist"
End If
Dim Path1 As String
Dim myfilename As String
Dim Name As String
Path1 = ToPath & "\Purchase Orders"
myfilename = "C" & Range("A3") & " " & "DCS Purchase Order" & ".xlsb"
Name = Path1 & "\" & myfilename & ".xlsb"
ActiveWorkbook.SaveAs Filename:=Name, _
FileFormat:=50, CreateBackup:=False
FSO.CopyFolder Source:=FromPath, Destination:=ToPath
MsgBox "You can find the files and subfolders in " & ToPath & "." & " " & "This Purchase Order sheet has been saved in the Purchase Orders folder"
End Sub
Bookmarks