• 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.

VBA PDF printout of a scorecard

Ernst B. Zwick

New Member
Hi!

I'trying to export a scorecards to a PDF file via a makro.
The specs: Win10 Home 64, Excel 2016, Adobe DC pro

Here's the attempt, which gave me errors:

---
Sub PDFPrint()
'
' PDFPrint Makro
'
' Keys: Strg+p
'
Sheets("Scorecard").Select
strTarget = "c:\Temp\FAS\"
ChDir (strTarget)
ActiveSheet.PageSetup.PrintArea = "$A$1:$L$59"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:="FAS_" & Range("Scorecard!C4").Value & ".pdf", _
Quality:=xlQualityStandard, _
IncudeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Sheets("Scorecard").Select

End Sub
---

The errors I'got were:
Runtime errror 1004
Application or object defines error
---

Any help would be greatly appreciated!
Thanky you,
Ernst



POST MOVED BY MODERATOR

.
 
Last edited by a moderator:
Hello Ersnt B, and welcome to the forum! :awesome:

This is the problem:

Range("Scorecard!C4").

Range should be a single cell address. If you want to specify a sheet, that would be a parent object, like:

Worksheets("Scorecard").Range("C4")

Full code:
Code:
Sub PDFPrint()
'
' PDFPrint Makro
'
' Keys: Strg+p
'

    Dim strTarget As String
    strTarget = "c:\Temp\FAS\"

    With Sheets("Scorecard")
        .PageSetup.PrintArea = "$A$1:$L$59"
        .ExportAsFixedFormat Type:=xlTypePDF, _
            Filename:=strTarget & "FAS_" & .Range("C4").Value & ".pdf", _
            Quality:=xlQualityStandard, _
            IncudeDocProperties:=True, _
            IgnorePrintAreas:=False, _
            OpenAfterPublish:=False
    End With

End Sub
 
Thank you for your help!
However, after changing the lines to your suggestions, I still got problems.
upload_2016-11-1_8-30-47.png
Thank you for looking at this again!
Best,
Ernst
 
When you hit the Debug/Debuggen button, which line gets highlighted? I'm going to guess is the ExportAsFixedFormat line. :(

Have you verified that the value in cell C4 of the Scorecard sheet has a valid name? No weird slashes or other symbols?
 
Hi!
Yes it was the ExportAsFixedFormat line and yes, there where symbols in the C4 cell. Got it running, thank you! :)
Best,
Ernst
 
Back
Top