Message Box Then Save File in Directory (Create if Inexistant)

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,
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,896
Messages
6,175,259
Members
452,626
Latest member
huntinghunter

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top