Consulting

Results 1 to 5 of 5

Thread: save certain sheets as a pdf from a closed wb

  1. #1
    VBAX Contributor
    Joined
    Apr 2008
    Posts
    136
    Location

    save certain sheets as a pdf from a closed wb

    Could some please help. I am looking to save certain sheets from a closed workbook as pdf files in a destination folder. This macro will be run daily. I have had a go to start this off with one sheet.
    Please could someone help.

    [VBA]
    Sub Test()
    Dim Sh As Worksheet
    Dim bled As Workbook

    'Where the sheets reside.
    Cops = "C:\Input\TheBook.xls"



    For Each Sh In bled

    Sheets(SheetCar).Select
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\Users\Output\SheetCar.pdf", Quality:=xlQualityStandard, _
    IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
    False

    Next
    End Sub
    [/VBA]

  2. #2
    VBAX Mentor
    Joined
    Jul 2012
    Posts
    398
    Location
    [VBA]Sub exportToPdf()
    Cops = "C:\Input\TheBook.xls"
    Workbooks.Open Filename:=Cops
    strFilePath = "C:\Users\Output\"
    Application.ScreenUpdating = False
    For Each Sh In Sheets
    strPdfName = Sh.Name & ".pdf"
    Sh.Copy
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=strFilePath & strPdfName, _
    Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=False
    ActiveWorkbook.Close (False)
    Next
    Application.ScreenUpdating = True
    End Sub[/VBA]

  3. #3
    VBAX Contributor
    Joined
    Apr 2008
    Posts
    136
    Location
    Thanks Patel I would like to select certain sheets not all to be saved as PDF's. How could I change the code to say only save Test1, Test5, Test6, Test7 as pdf's?

  4. #4
    VBAX Contributor
    Joined
    Apr 2008
    Posts
    136
    Location
    I have managed to figure the code for this, and will post soon to share. Now I just have to figure out how to prompt the user for a location as it will change on a daily basis.

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    [VBA]Private Sub SaveWB()

    Dim UserDirectory As String

    UserDirectory = Get_Folder("Enter directory path where ReadMe is to be placed:")
    If UserDirectory = "" Then Exit Sub
    UserDirectory = UserDirectory & "/"

    ActiveWorkbook.SaveAs FileName:=UserDirectory & "test.xls"

    End Sub

    Private Function Get_Folder(Optional HeaderMsg As String) As String
    With Application.FileDialog(msoFileDialogFolderPicker)
    .initialFilename = Application.DefaultFilePath
    .Title = HeaderMsg
    If .show = -1 Then
    Get_Folder = .SelectedItems(1)
    Else
    Get_Folder = ""
    End If
    End With
    End Function[/VBA]

Posting Permissions

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