• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

getting error 1004

dear all

i m getting error when i click on print in PDF button. below i m using the code

And i m getting error on this (Sheets(Sheets.Count).Name = c.value)

Pls help me out

Code:
Sub GeneratePDF()

Application.ScreenUpdating = False

Dim c As Range
Dim lastrow, i As Integer
Dim Shtnames As Variant
Dim sFileName As String
ReDim Shtnames(0)

lastrow = Sheets("DATA").Columns("H").Cells(Rows.Count).End(xlUp).row

For Each c In Sheets("DATA").Range("H2:H" & lastrow)
If c.value <> 0 Then
Sheets("BILL").Range("E7").value = c.value
Sheets("BILL").Copy After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = c.value
Shtnames(UBound(Shtnames)) = CStr(c.value)
ReDim Preserve Shtnames(UBound(Shtnames) + 1)
End If
Next c

ReDim Preserve Shtnames(UBound(Shtnames) - 1)
Sheets(Shtnames).Select

Path = Sheets("BILL").Range("folderPath").value

sFileName = Path & "Advice_" & Sheets("BILL").Range("J12").value & ".pdf"

ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
sFileName, Quality:=xlQualityStandard, IgnorePrintAreas:=False, OpenAfterPublish:= _
True

Application.DisplayAlerts = False
Sheets(Shtnames).Delete
Application.DisplayAlerts = True

Application.ScreenUpdating = True

End Sub
 
Last edited by a moderator:
Hi Marc

I dnt know vba coding i m just a new born for VBA coding but from searching on google i create a sheet which i same shared you earlier. pls look into it. and resolve pls sir
 

It looks like a data problem, so depending of c value …

Bad value, duplicate, … Just check !
 

No, I can't run your file and as you can - must - check data …

When error occurs, what is c value ?​
 
Back
Top