Issues with macro not working anymore

jadams121

New Member
Joined
Jul 18, 2019
Messages
12
Good afternoon,

I'm new to VB and I found this code, which worked for me perfectly fineyesterday, but now it just stopped doing anything. Does anyone know why itstopped, or is there something obvious I need to consider when trying totroubleshoot it? file path I correct, as are the cell locations referenced

Thank you in advance.


'-------------------------------------------------------------------------------
Sub Save_as_Pdfs()
'-------------------------------------------------------------------------------
' Saves marked sheets as PDF file.

Const PDF_path = "D:\PDF"

Dim Snr As Integer
Dim Name As String

'Process all sheets in workbook
For Snr = 1 To ActiveWorkbook.Sheets.Count
Sheets(Snr).Activate
'Only print if c4 contains "NOTE"
If Cells(4, "C").Value = "NOTE" Then
Name = PDF_path & ActiveSheet.Name & Cells(4, "B").Value & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=False
End If
Next Snr
End Sub

 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
.
This works here :

Code:
Option Explicit


'-------------------------------------------------------------------------------
Sub Save_as_Pdfs()
'-------------------------------------------------------------------------------
' Saves marked sheets as PDF file.
Dim PDF_path As String
Dim Snr As Integer
Dim Name As String


PDF_path = "C:\Users\My\Desktop\PDF\"   'edit path as required


On Error Resume Next


'Process all sheets in workbook
For Snr = 1 To ActiveWorkbook.Sheets.Count
    Sheets(Snr).Activate
    'Only print if c4 contains "NOTE"
    If Cells(4, "C").Value = "NOTE" Then
        Name = PDF_path & ActiveSheet.Name & Cells(4, "B").Value & ".pdf"
        ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=Name, _
        Quality:=xlQualityStandard, IncludeDocProperties:=False, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
    End If
Next Snr
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

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