VBA making folder and saving workbook?

Soldato
Joined
30 Dec 2005
Posts
2,522
Hi all

i am having some issues saving an Excel workbook after creating a folder, not sure how to get to save the work book after the folder has been created :confused:

I got it to create the folder in the "2017" Folder but can't get it to save the workbook in that created folder after, any ideas? What do i need after path to get it to the new folder?

Code:
Sub Makefoldersaver()

'Creates New Folder

Dim FSO
Dim sFolder As String
Dim Ref
Ref = Sheets("Input").Range("T4").Value

sFolder = "C:\Users\User\Documents\Shipments\2017\" & Sheets("Input").Range("T4").Value

Set FSO = CreateObject("Scripting.FileSystemObject")

If Not FSO.FolderExists(sFolder) Then
FSO.CreateFolder (sFolder) 'Checking if the same Folder already exists

Else
MsgBox Ref & " Folder Already Exists", vbExclamation, "Folder Already Exists!"
End If

Dim Filename As String
Dim Path As String

Application.DisplayAlerts = False

Path = "C:\Users\User\Documents\Shipments\2017\"
Filename = Range("T6").Value & ".xlsx"
ActiveWorkbook.SaveAs Path & Filename, xlOpenXMLWorkbook

Application.DisplayAlerts = True

ActiveWorkbook.Close

End Sub

Thanks guys, was never good at Excel!
 
Soldato
OP
Joined
30 Dec 2005
Posts
2,522
Yep, I needed to add another line so it would save in the folder created

sFolder2 = "C:\Users\User\Documents\Shipments\2017\" & Sheets("Input").Range("T4").Value & "\" & Sheets("Input").Range("T5").Value

and

ActiveWorkbook.SaveAs FileName:=sFolder2 & Ref

Cheers!
 
Back
Top Bottom