jay_the_cob
New Member
- Joined
- May 23, 2018
- Messages
- 7
I am a beginner at VBA and am trying to create a button that will open a message box notifying the user he is about to save a pdf copy of the workbook. If Yes, it proceeds to verifying whether the dynamic directory exists (creates if not), then saves the file there. If No, simply does nothing.
My message box is working fine, and the button attempts to save the file, but it is unable to create the directory since it does not currently exists.
All help is appreciated.
Sub GetAnswerAndSavedPDF()
Dim Msg As String, Ans As Variant
Msg = "Do you wish to proceed with saving a PDF backup of this Oversight Dashboard?'"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
If Not FileFolder("\\Mflccg02\Cash Admin\Montreal\Jacob\Management\TEST" & Format(Now(), "YYYY") & "" & Format(Now(), "MMMM YYYY")) Then
MkDir ("\\Mflccg02\Cash Admin\Montreal\Jacob\Management\TEST" & Format(Now(), "YYYY") & "" & Format(Now(), "MMMM YYYY"))
End If
ThisWorkbook.Sheets(Array("Oversight", "KPI Tracking")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"\\Mflccg02\Cash Admin\Montreal\Jacob\Management\TEST" & Format(Now(), "YYYY") & "" & Format(Now(), "MMMM YYYY") & "\Oversight Report - " & Format(Now(), "MM.DD.YYYY") & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Application.DisplayAlerts = False
Case vbNo
GoTo Quit:
End Select
Quit:
End Sub
Public Function FileFolder(strFULLPath As String) As Boolean
If Not Dir(strFULLPath, vbDirectory) = vbNullString Then FileFolder = True
On Error GoTo 0
End Function
Thanks,
My message box is working fine, and the button attempts to save the file, but it is unable to create the directory since it does not currently exists.
All help is appreciated.
Sub GetAnswerAndSavedPDF()
Dim Msg As String, Ans As Variant
Msg = "Do you wish to proceed with saving a PDF backup of this Oversight Dashboard?'"
Ans = MsgBox(Msg, vbYesNo)
Select Case Ans
Case vbYes
If Not FileFolder("\\Mflccg02\Cash Admin\Montreal\Jacob\Management\TEST" & Format(Now(), "YYYY") & "" & Format(Now(), "MMMM YYYY")) Then
MkDir ("\\Mflccg02\Cash Admin\Montreal\Jacob\Management\TEST" & Format(Now(), "YYYY") & "" & Format(Now(), "MMMM YYYY"))
End If
ThisWorkbook.Sheets(Array("Oversight", "KPI Tracking")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"\\Mflccg02\Cash Admin\Montreal\Jacob\Management\TEST" & Format(Now(), "YYYY") & "" & Format(Now(), "MMMM YYYY") & "\Oversight Report - " & Format(Now(), "MM.DD.YYYY") & ".pdf" _
, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
Application.DisplayAlerts = False
Case vbNo
GoTo Quit:
End Select
Quit:
End Sub
Public Function FileFolder(strFULLPath As String) As Boolean
If Not Dir(strFULLPath, vbDirectory) = vbNullString Then FileFolder = True
On Error GoTo 0
End Function
Thanks,