+ Reply to Thread
Results 1 to 17 of 17

Print/Saving a perticular sheet as PDF

Hybrid View

5habbaranks Print/Saving a perticular... 09-13-2011, 10:21 AM
Domski Re: Print/Saving a perticular... 09-13-2011, 10:24 AM
5habbaranks Re: Print/Saving a perticular... 09-13-2011, 10:37 AM
Domski Re: Print/Saving a perticular... 09-13-2011, 10:40 AM
5habbaranks Re: Print/Saving a perticular... 09-13-2011, 10:46 AM
5habbaranks Re: Print/Saving a perticular... 09-13-2011, 10:50 AM
Domski Re: Print/Saving a perticular... 09-13-2011, 10:54 AM
5habbaranks Re: Print/Saving a perticular... 09-13-2011, 11:01 AM
Domski Re: Print/Saving a perticular... 09-13-2011, 11:20 AM
5habbaranks Re: Print/Saving a perticular... 09-13-2011, 11:29 AM
Domski Re: Print/Saving a perticular... 09-13-2011, 11:36 AM
5habbaranks Re: Print/Saving a perticular... 09-13-2011, 11:44 AM
Domski Re: Print/Saving a perticular... 09-13-2011, 11:50 AM
5habbaranks Re: Print/Saving a perticular... 09-13-2011, 11:59 AM
Domski Re: Print/Saving a perticular... 09-13-2011, 12:03 PM
5habbaranks Re: Print/Saving a perticular... 09-13-2011, 12:03 PM
Domski Re: Print/Saving a perticular... 09-13-2011, 12:15 PM
  1. #1
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Print/Saving a perticular sheet as PDF

    Hi all..

    I have a workbook with 3 sheets. On sheet 1 I have macro buttons 1 of which "prints/saves as pdf" the current/active sheet. I would like to add a button which "prints/saves as pdf" sheet 2. How is this possible please?

    Thanks

  2. #2
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Print/Saving a perticular sheet as PDF

    Sure, can you post the code you have so far.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  3. #3
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Print/Saving a perticular sheet as PDF

    Im sorry... Here it is
    Sub Convert2PDF()
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     sFileName, Quality _
     :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
     OpenAfterPublish:=True
    End Sub

  4. #4
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Print/Saving a perticular sheet as PDF

    It would be like this:

    Sub Convert2PDF()
    Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     sFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
     IgnorePrintAreas:=False, OpenAfterPublish:=True
    End Sub

    Dom

  5. #5
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Print/Saving a perticular sheet as PDF

    Fandabby dozy - thank you.

  6. #6
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Print/Saving a perticular sheet as PDF

    I dont suppose you know how to specify a file name for it to save as? Not a file location just file name? Thanks

  7. #7
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Print/Saving a perticular sheet as PDF

    Can't test this but maybe:

    Sub Convert2PDF()
    Dim strFileName As String
    strFileName = ThisWorkbook.Path & "\MyFile.pdf"
    Sheets("Sheet2").ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     strFileName, Quality:=xlQualityStandard, IncludeDocProperties:=True, _
     IgnorePrintAreas:=False, OpenAfterPublish:=True
    End Sub

    Dom

  8. #8
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Print/Saving a perticular sheet as PDF

    Thanks for trying, unfortunatly it still saves the pdf as the original workbook name

  9. #9
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Print/Saving a perticular sheet as PDF

    Odd I thought that would work. I assume you've saved the workbook before running the code?

    Dom

  10. #10
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Print/Saving a perticular sheet as PDF

    Yeah I saved it, even closed it down and then reopend it. The code is as below:
    Sub Convert2PDF()
    Dim strFileName As String
    strFileName = ThisWorkbook.Path & "\test1.pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     sFileName, Quality _
     :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
     OpenAfterPublish:=True
    End Sub

  11. #11
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Print/Saving a perticular sheet as PDF

    Nearly, I'd called the variable strFileName:

    Sub Convert2PDF()
    Dim strFileName As String
    strFileName = ThisWorkbook.Path & "\test1.pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     strFileName, Quality _
     :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
     OpenAfterPublish:=True
    End Sub

    Dom

  12. #12
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Print/Saving a perticular sheet as PDF

    Ah ha!! Cool that works fine... Thanks..

    I notice you can name the pdf based on a cell content, is it possible to append a cell field infront of the "\test1.pdf" so it would read "\test1-cellcontent.pdf"?

    Thanks

  13. #13
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Print/Saving a perticular sheet as PDF

    Like this:

    strFileName = ThisWorkbook.Path & "\test1-" & Range("A1").Value & ".pdf"

    Dom

  14. #14
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Print/Saving a perticular sheet as PDF

    Exactly like that only it didnt work, Ive got my str's in place this time

    Sub Convert2PDF()
    Dim strFileName As String
    strFileName = ThisWorkbook.Path & "\test1-" & Range("A1").Value & ".pdf"
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     strFileName, Quality _
     :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
     OpenAfterPublish:=True
    End Sub

  15. #15
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Print/Saving a perticular sheet as PDF

    It will be picking the cell info up from cell A1 on the active worksheet. Is this how you have it set up?

    Dom

  16. #16
    Registered User
    Join Date
    12-07-2010
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Print/Saving a perticular sheet as PDF

    Excuse my utter stupidity I accidently labled the cell with nothing in it - doh. Works perfectly thanks

  17. #17
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Print/Saving a perticular sheet as PDF

    No worries. Please mark the thread Solved if you're happy with the solution.

    Dom

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1