MY code is posted below. I need to create a folder with the name in cell "E10" of Sheet1. I then need to save a copy of sheet1 in it as a PDF with a name and timestamp (date & time). Any help would be greatly appreciated. I've been stuck on this for awhile. Thanks.
Public Sub SaveToDesktop()
Dim Value As String
On Error GoTo MyError
Set Value = Worksheets("Sheet1").Cells(10, "E").Value
Filename1 = "C:\Users\" & Environ$("Username") & "\Desktop\" & Value
Filename2 = "C:\Users\" & Environ$("Username") & "\Desktop\" & Value & "Sheet1" & Now() & ".pdf"
'Checks for a folder
Fdir = Filename
Set FSO = CreateObject("Scripting.FileSystemObject")
'Checks for a folder and creates it with the date
Fdir = Filename
Set FSO = CreateObject("Scripting.FileSystemObject")
If Not FSO.FolderExists(Fdir) Then
FSO.CreateFolder (Fdir)
End If
TheMessage = "Folder has been created named " & Filename
Beep
MsgBox TheMessage, vbInformation, "Folder Created"
ThisWorkbook.SaveAs Filename2
MyExit:
Exit Sub
'this handles an error for data mismatch
MyError:
If Err.Number = 13 Then GoTo MyExit
MsgBox Err.Description
GoTo MyExit
End Sub
Bookmarks