macro is skipping tabs

jadams121

New Member
Joined
Jul 18, 2019
Messages
12
good morning,

Newbie here...i have a macro for auto generating tabs into PDFs and save them. the issue i'm having is that it is randomly skipping over some of the tabs. anyone have an idea how to fix this?

I checked the ones that get skipped to see if cell "A5" is the problem but it is not, as it has the exact same cell value but chooses to generate randomly (although its consistently the same tabs, and never different ones)...i have no idea how else to audit this.

please help, and thank you in advance!

Code:
[TABLE="width: 493"]
<colgroup><col></colgroup><tbody>[TR]
[TD]Option Explicit[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]'-------------------------------------------------------------------------------[/TD]
[/TR]
[TR]
[TD]Sub Save_as_Pdfs()[/TD]
[/TR]
[TR]
[TD]'-------------------------------------------------------------------------------[/TD]
[/TR]
[TR]
[TD]' Saves marked sheets as PDF file.[/TD]
[/TR]
[TR]
[TD]Dim PDF_path As String[/TD]
[/TR]
[TR]
[TD]Dim Snr As Integer[/TD]
[/TR]
[TR]
[TD]Dim Name As String[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]PDF_path = "d:\PDF\"   'edit path as required[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]On Error Resume Next[/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
[TR]
[TD]'Process all sheets in workbook[/TD]
[/TR]
[TR]
[TD]For Snr = 1 To ActiveWorkbook.Sheets.Count[/TD]
[/TR]
[TR]
[TD]    Sheets(Snr).Activate[/TD]
[/TR]
[TR]
[TD]    'Only print if A5 contains "YES"[/TD]
[/TR]
[TR]
[TD]    If Cells(5, "A").Value = "YES" Then[/TD]
[/TR]
[TR]
[TD]        Name = PDF_path & ActiveSheet.Name & Cells(4, "B").Value & ".pdf"[/TD]
[/TR]
[TR]
[TD]        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _[/TD]
[/TR]
[TR]
[TD]        Quality:=xlQualityStandard, IncludeDocProperties:=False, _[/TD]
[/TR]
[TR]
[TD]        IgnorePrintAreas:=False, OpenAfterPublish:=False[/TD]
[/TR]
[TR]
[TD]    End If[/TD]
[/TR]
[TR]
[TD]Next Snr[/TD]
[/TR]
[TR]
[TD]End Sub[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Remove this line & see what happens
Code:
On Error Resume Next
 
Upvote 0
What happens if you change this line:

If Cells(5, "A").Value = "YES" Then

to this:

If Ucase(Trim(Cells(5, "A").Value)) = "YES" Then
 
Upvote 0
thanks for the help, but now i get a "run time error 1004" at the first tab that it starts skipping tabs
 
Upvote 0
What is the error message & which line of code is highlighted when you click debug?
 
Upvote 0
this entire area is highlighted:

Code:
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
        Quality:=xlQualityStandard, IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
 
Upvote 0
And the error message?

Also what is the value of Cells(4,"B") on the sheet it fails on?
 
Last edited:
Upvote 0
1004 is the error number, not the error message ;)

Yes the problem is the / as it is an illegal character for a filename
 
Last edited:
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,700
Members
448,293
Latest member
jin kazuya

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