jyothisurya111
New Member
- Joined
- Feb 18, 2021
- Messages
- 7
- Office Version
- 365
- Platform
- 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
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