I'm working on a macro that will export each page as a jpg. It's mostly working, but I'm getting stuck when the following page is blank and I want to move to the next page.
That IF THEN statement is where I'm getting confused.Thanks!
Sub ExportPagesJPG() Dim path As String, sfolder As String Dim i As Long Dim p As Page sfolder = CorelScriptTools.GetFolder("D:\Sync\Tagify\") 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 ActivePage.Next.Activate 'Sets the export path and files name path = sfolder & "\" & ActivePage.Name & ".jpg" '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 Next p End Sub
You have an "If" without a corresponding "End If" statement; not so good.
I don't think you want to activate the next page right there; you just want to go to the next iteration of your loop-through-the-pages thing without trying to export the contents of the empty page.
So, something more like this:
Sub ExportPagesJPG() Dim path As String, sfolder As String Dim i As Long Dim p As Page Dim expflt As ExportFilter sfolder = CorelScriptTools.GetFolder("D:\Sync\Tagify\") For Each p In ActiveDocument.Pages p.Activate 'Select objects on page ActiveLayer.Shapes.All.CreateSelection 'If objects selected, then export If ActiveSelectionRange.Count > 0 Then 'Sets the export path and files name path = sfolder & "\" & ActivePage.Name & ".jpg" '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 End Sub
Working like a charm! I knew it was the way I was structuring it was wrong but was getting stuck. Thank you as always!
Hey, cool, I'm glad to hear that you're trying stuff, asking questions when you get stumped, and getting some good results.
I don't know if you have looked at this, but I have heard good things about it from some other users:
wOxxOm Multipage Export to Bitmaps.