Create me an excel VBA macro code that creates a folder that is titled with the contents…
- User
Create me an excel VBA macro code that creates a folder that is titled with the contents of A1 and A2 with a _ in the title that separates the contents of A1 from A2
- Assistant
Sure! Here's a code that will create a folder with the title based on the contents of cells A1 and A2:
Sub CreateFolder() Dim folderPath As String ' Path of the folder where you want to create the new folder folderPath = "C:\Your\Folder\Path" ' Create the folder name based on the contents of A1 and A2 Dim folderName As String folderName = Range("A1").Value & "_" & Range("A2").Value ' Create the new folder MkDir folderPath & "\" & folderName ' Display a message box with the created folder path MsgBox "Folder created with the name: " & folderPath & "\" & folderName End SubReplace
"C:\Your\Folder\Path"with the path where you want to create the new folder. You can modify the folder path as per your requirements. - User
Next create a .pdf file titled the cell contents of A1 and 2. Add a _ separating the contents. Add an underscore after the contents of A3 and add Supporting Documents. Place it in the folder you previously created. Do this for cell A2-A8.
- Assistant
Certainly! Here's an updated code that will create a PDF file with the specified title for the contents of cells A1 and A2, and place it in the previously created folder. Additionally, it will create PDF files for cell A2 to A8, with a modified title as per your instructions.
Sub CreatePDF() Dim folderPath As String Dim folderName As String Dim fileName As String Dim ws As Worksheet Set ws = ThisWorkbook.ActiveSheet ' Path of the folder where you want to create the new folder folderPath = "C:\Your\Folder\Path" folderName = ws.Range("A1").Value & "_" & ws.Range("A2").Value ' Create the new folder if it doesn't exist If Len(Dir(folderPath & "\" & folderName, vbDirectory)) = 0 Then MkDir folderPath & "\" & folderName End If ' Loop through cells A2 to A8 to create PDF files Dim i As Long For i = 2 To 8 fileName = ws.Range("A" & i).Value & "_" & ws.Range("A1").Value & "_" & ws.Range("A2").Value & "_Supporting Documents" ' Save worksheet as PDF ws.ExportAsFixedFormat Type:=xlTypePDF, _ Filename:=folderPath & "\" & folderName & "\" & fileName, _ Quality:=xlQualityStandard, _ IncludeDocProperties:=True, _ IgnorePrintAreas:=False ' Display a message box with the created PDF file path MsgBox "PDF file created with the name: " & folderPath & "\" & folderName & "\" & fileName & ".pdf" Next i End Sub