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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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
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,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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