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

 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Logit

Well-known Member
Joined
Aug 31, 2016
Messages
3,344
.
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
 

Watch MrExcel Video

Forum statistics

Threads
1,102,463
Messages
5,487,029
Members
407,576
Latest member
aapnarritesh

This Week's Hot Topics

Top