How to Create a Folder in VBA

tkoral

New Member
Joined
Dec 6, 2012
Messages
8
Hi!

This is my first post here, so bare with me.

I've done some incredibly extensive research and can't quite find what I need. I'm quite a novice when it comes to VBA and have been attempting to stumble my way through creating what I'd like to create. Either way, here goes.

I have a large Excel file with dozens of tabs that I'd like to create a Macro/Function for. On one tab, I have a "Create PDF" button which, when clicked, selects four specified tabs, and saves a PDF file to a folder on my C drive.

Sub PDF_Generator3()
'
' PDF_Generator3 Macro
'
'
Sheets(Array("Ancillary Performance", "Retail-Lease Performance", _
"Used Performance", "District KPIs")).Select
Sheets("Ancillary Performance").Activate
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, FileName:="C:\Region Business Update\" & Range("C3"), _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas _
:=False, OpenAfterPublish:=False
ActiveWorkbook.Save
End Sub

I figured out how to create a function to name the file based on a cell reference, which is perfect, but I'm looking for something a little more in depth.

The Region Business Update folder may not exist on everyone's C drive who uses this Excel file, so this is what I'm looking for: I'd like the Macro/Function to perform the above action, but create the Region Business Update folder, if it doesn't already exist. If it does exist, I'd like it to move on and create a folder based on cell P8 on the Ancillary Performance tab, which is a Date (MM-YY). If the date already exists, I'd like it to move forward. Lastly, I'd like it to save the PDF file within the appropriate date folder.

If anyone can assist with this, I would SUPER appreciate it.

Thanks in advance and have a great day.
 
Last edited:

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Call the Dir function to check whether a folder exists. Call the MkDir function to create a folder. I couldn't really follow the rest of your post, so maybe someone else can help with that.
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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