+ Reply to Thread
Results 1 to 3 of 3

Macro to pull in the worsheet name to save it as a PDF.

Hybrid View

aadeshgandhi Macro to pull in the worsheet... 03-18-2013, 05:03 PM
SEOSEO.dk Re: Macro to pull in the... 03-19-2013, 02:40 AM
aadeshgandhi Re: Macro to pull in the... 03-19-2013, 10:17 AM
  1. #1
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    87

    Macro to pull in the worsheet name to save it as a PDF.

    Hello,
    When I run the macro I would it to save it to a PDF and also choose the name for a PDF based on the worsheet name. I have the macro setup in which its prints the selected sheet but I have to manually enter the name for each PDF. How to write to code so that the name = worksheet name? Below is the code.
    Printer can be either Adobe PDF or CutePDF.
    Sub PrintAll()
         Application.Dialogs(xlDialogPrinterSetup).Show
        Dim ws As Worksheet
        Application.DisplayAlerts = False
        For Each ws In ActiveWorkbook.Worksheets
            If ws.Name = "t1" Or ws.Name = "t2" Or ws.Name = "Sheet11" Or ws.Name = "Sheet12" Then
            Else
                ws.Visible = xlSheetVisible
                WHAT SHOULD GO HERE SO THAT IT PULLS IN THE WORKSHEET NAME FOR THE SAVE AS DIALOG BOX THAT OPENS UP. 
                ws.PrintOut
                
            End If
        Next ws
        Application.DisplayAlerts = True
    End Sub


    Thanks,
    Aadesh Gandhi

  2. #2
    Registered User
    Join Date
    01-31-2013
    Location
    Xuzhou
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro to pull in the worsheet name to save it as a PDF.

    I do NOT have the answer - but exactly the same issue. Look forward to see the administrators answer! Thank you aadeshgandhi to post this issue.

  3. #3
    Registered User
    Join Date
    08-13-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: Macro to pull in the worsheet name to save it as a PDF.

    Quote Originally Posted by SEOSEO.dk View Post
    I do NOT have the answer - but exactly the same issue. Look forward to see the administrators answer! Thank you aadeshgandhi to post this issue.
    SEOSEO,
    I was able to get two ways for it to work,
    1) This will save the PDF in the same directory as the worksheet.
    Sub SheetsToPDFs()
    
        Dim strPath As String
        Dim ws As Worksheet
    
        strPath = ActiveWorkbook.Path & "\"
        
        For Each ws In ActiveWorkbook.Worksheets
            If ws.Name = "A" Or ws.Name = "B" Or ws.Name = "C" Or ws.Name = "D" Or ws.Name = "E" Or ws.Name = "F" Then
            Else
            ws.ExportAsFixedFormat xlTypePDF, strPath & ws.Name & ".pdf"
            End If
        Next ws
            
    End Sub
    2) This will save the PDF to the desktop.



    Sub SheetsToPDFs()
    
        Dim DeskTop As String
        DeskTop = CreateObject("WScript.Shell").SpecialFolders("Desktop")
        Dim ws As Worksheet
    
        
        For Each ws In ActiveWorkbook.Worksheets
            If ws.Name = "A" Or ws.Name = "B" Or ws.Name = "C" Or ws.Name = "D" Or ws.Name = "E" Or ws.Name = "F" Then
            Else
            ws.ExportAsFixedFormat xlTypePDF, Filename:=DeskTop & Application.PathSeparator & ws.Name & ".pdf"
            End If
        Next ws
            
    End Sub

    I hope this works for you.



    Thanks,
    Aadesh Gandhi

+ 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