excel worksheets to pdf

How to create pdf file from each tab and name the file based on the cell "E3". the pdf file should pick column A to K and to the last active row in column K. below is the code that i found on internet


Sub createPDFfiles()
    Dim ws As Worksheet
    Dim try As String
    For Each ws In ActiveWorkbook.Worksheets
        On Error Resume Next

       
         try = ActiveWorkbook.Name & "-" & ws.Name

         try =  “D:\split the invoice\New folder\” & ActiveWorkbook.Name & "-" & ws.Name
       
        ws.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=try, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False
    Next ws
End Sub
NirvanamanagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,
pls try

Sub macro()

For Each sh In ActiveWorkbook.Sheets
    Set rng = sh.Range(SH.Range("A1"), sh.Range("K" & Cells.Rows.Count).End(xlUp))
    fPathFile = sh.Range("e3")
    rng.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fPathFile, quality:=xlQualityStandard, _
        includedocproperties:=True, ignoreprintareas:=True, openafterpublish:=True
Next
End Sub

Open in new window

Regards
0
Kanti PrasadCommented:
Hi

The below will pick the value from E3 which is Cells(3,5) and name the pdf accordingly.

Sub createPDFfiles()
    Dim ws As Worksheet
    Dim try As String
    For Each ws In ActiveWorkbook.Worksheets
        On Error Resume Next
   
         try = ws.Cells(3, 5)
       '  try =  “c:\” & ws.Cells(3, 5)
       Set AtoK = ws.Range(ws.Range("A1"), ws.Range("K" & Cells.Rows.Count).End(xlUp))
        AtoK.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=try, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False
    Next ws
End Sub
0
NirvanamanagerAuthor Commented:
Hi Thank you very much for a very quick reply for some reason i am not able to get all the rows in the pdf. am i doing something wrong?

pdf should have all the contents from Columns  A column k and all the active row starting from A1 in the attached file i need the pdf to have contents from cell A1 to L 55
sample.xlsx
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Kanti PrasadCommented:
Hi

I am not sure what you want but change the K to L55 so you should have all the data from A1 to L55
0
NirvanamanagerAuthor Commented:
@kanti
sorry if i was not able to articulate it properly from row 1 to 9 I have no data in columns A and B from row 9 i have data in rows

something like below code but do not know how to make it work

Sub createPDFfiles()
    Dim ws As Worksheet
    Dim try As String
    For Each ws In ActiveWorkbook.Worksheets
        On Error Resume Next
   
         try = ws.Cells(3, 5)
       '  try =  “c:\” & ws.Cells(3, 5)
       Set AtoK = ws.Range(ws.Range("A1"), ws.Range("L8" & Cells.Rows.Count))
       Set AtoK = ws.Range(ws.Range("A9"), ws.Range("L" & Cells.Rows.Count).End(xlUp))
        AtoK.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=try, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False
    Next ws
End Sub

Open in new window


sample.png
0
Kanti PrasadCommented:
Hi

So you just need the invoice no and the rows from A9 to end of sheet  right?
Just remove this line
 Set AtoK = ws.Range(ws.Range("A1"), ws.Range("L8" & Cells.Rows.Count))
0
NirvanamanagerAuthor Commented:
Hi

I need the data from A1 to J1537
0
Rgonzo1971Commented:
pls try

 Set AtoK = ws.Range(ws.Range("A1"), ws.Range("J" & Cells.Rows.Count).End(xlup))
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NirvanamanagerAuthor Commented:
Thank you thank you.. super.. works beautifully
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.