Automatic printing of Active excel sheets to PDF

jyothisurya111

New Member
Joined
Feb 18, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I have a active excel sheet with the Title "Invoice " on which i have given the below attached code for few days it run well but now its giving Runtime error code 1004 against the code line marked in "RED"

Code used :
Sub DateToForm3()

Application.ScreenUpdating = False 'Speed up macro
Application.DisplayAlerts = False 'Speed up macro

Dim i As Long, svNm As String, fPath As String
Dim Sh As Worksheet, ShCS As Worksheet
Dim MyRange As Range, MyVal As Range, LR As Long

Set Sh = Sheets("Invoice")
Set ShCS = Sheets("Vendor Info")

LR = ShCS.Range("A" & Rows.Count).End(xlUp).Row

fPath = Sheets("Invoice").Range("I8").Value
For i = 2 To LR 'Loop through 5 to last row number
Sh.Cells(14, 8) = ShCS.Cells(i, 1)
Sh.PrintOut 'Print statements sheet
svNm = Sh.Cells(2, 10) & ".pdf"
Application.PrintCommunication = True
ChDir fPath
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPath & svNm, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False

Next i 'go back and do next row in loop

Sh.Cells(14, 8).ClearContents 'Clear Statements "H14" cell contents & You can edit this content number when you have a situation to chnage this cell reference

Err: 'Error handling and end of code to turn screen updating and display events back on
Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
 

Attachments

  • Picture1.png
    Picture1.png
    23.1 KB · Views: 3
  • Picture2.png
    Picture2.png
    60.9 KB · Views: 3

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.

Domenic

MrExcel MVP
Joined
Mar 10, 2004
Messages
19,726
Maybe your path and filename are missing a backslash???

VBA Code:
Filename:=fPath & "\" & svNm
 

Forum statistics

Threads
1,141,707
Messages
5,707,980
Members
421,539
Latest member
zuniBM

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
Top