1

good afternoon all, i am using the following code on my spreadsheet to save the file in a specific folder with a specific format:

Const csPath As String = "C:\Stationery Orders\"
MyName = ActiveWorkbook.Name
ActiveWorkbook.SaveAs Filename:=csPath & Sheets("Stationery").Cells(1, 1) & Format(CStr(Now), "ddmmyyyy_hhmm") & "  " & MyName & ".xlsm", FileFormat:=52

my problem is that i can't find a way to create this folder C:\Stationery Orders\ if the folder doesn't exist and also paste a shortcut on the user's desktop. Is that even possible? any ideas?

kind regards

2 Answers 2

1

Put a check before doing SaveAs. Something like,

If Dir(csPath, vbDirectory) = "" Then MkDir csPath

Then do the SaveAs

Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much for your replies, they both work but this one is easier to implement.
0

Try this. It will check if folder exists and create it if it doesn't exist.

Sub MyCuteSub()
    Dim FSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    If Not FSO.FolderExists("C:\temp\temptemptemp") Then
        FSO.CreateFolder ("C:\temp\temptemptemp")
    End If
End Sub

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.