I created a macro that exports each page in the document to a specific folder with a specific name.
https://imgur.com/Rsxe23e Folder path: D:\Sync\Tagify\Bud Light\Promotional\NFL\2023\Chargers\FixedFile name: Chargers@Case Card - 11x17@Fixed@I'm going back through my code to try and improve it. I'm trying to separate the steps into separate subs, or functions and calling them. However I'm having a hard time getting the values for the folder path and file name. Not sure if I'm doing this right.
Private Sub Export_Click() Dim sFileName As String, path As String Dim p As Page Dim expflt As ExportFilter 'Set File Name Call Get_File_Name(sFileName) MsgBox "sFileName: " & sFileName 'returns nothing. 'Set Path Call Get_File_Name MsgBox "path: " & path 'Export All Pages For Each p In ActiveDocument.Pages p.Activate 'Select objects on page ActiveLayer.Shapes.All.CreateSelection 'If no objects selected, go to next page If ActiveSelectionRange.Count > 0 Then 'Exports jpg Set expflt = ActiveDocument.ExportBitmap(path, cdrJPEG, cdrSelection, cdrRGBColorImage, 0, 0, 300, 300, cdrNormalAntiAliasing, False, True, True, False, cdrCompressionNone) With expflt .Smoothing = 50 .Compression = 15 .Finish End With End If Next p 'Open folder of exported signs Call Shell("explorer.exe" & " " & path, vbNormalFocus) End Sub
Function Get_File_Name(sFileName As String) As String Dim sFileName As String 'Priced If Priced.Value = True And FrmMain.En_Y.Value = "" Then 'No Expiration Date sFileName = FrmMain.Title.Value & "@" & ActivePage.Name & "@" & "Priced" & "@" & FrmMain.Tagify_Brand.Value ElseIf Priced.Value = True And FrmMain.En_Y.Value <> "" Then 'With Expiration Date sFileName = FrmMain.Title.Value & "@" & ActivePage.Name & "@" & "Priced" & "@" & Format(Now, "mm-dd-yyyy") & "@" & FrmMain.En_M.Value & "-" & FrmMain.En_D.Value & "-" & FrmMain.En_Y.Value & "@" & FrmMain.Tagify_Brand.Value End If 'Fixed If Fixed.Value = True And FrmMain.En_Y.Value = "" Then 'No Expiration Date sFileName = FrmMain.Title.Value & "@" & ActivePage.Name & "@" & "Fixed" & "@" & FrmMain.Tagify_Brand.Value ElseIf Fixed.Value = True And FrmMain.En_Y.Value <> vbNull Then 'With Expiration Date sFileName = FrmMain.Title.Value & "@" & ActivePage.Name & "@" & "Fixed" & "@" & Format(Now, "mm-dd-yyyy") & "@" & FrmMain.En_M.Value & "-" & FrmMain.En_D.Value & "-" & FrmMain.En_Y.Value & "@" & FrmMain.Tagify_Brand.Value End If 'Template If Template.Value = True And FrmMain.En_Y.Value = "" Then 'No Expiration Date sFileName = FrmMain.Title.Value & "@" & ActivePage.Name & "@" & "Template" & "@" & FrmMain.Tagify_Brand.Value ElseIf Template.Value = True And FrmMain.En_Y.Value <> "" Then 'With Expiration Date sFileName = FrmMain.Title.Value & "@" & ActivePage.Name & "@" & "Template" & "@" & Format(Now, "mm-dd-yyyy") & "@" & FrmMain.En_M.Value & "-" & FrmMain.En_D.Value & "-" & FrmMain.En_Y.Value & "@" & FrmMain.Tagify_Brand.Value End If End Function