Results 1 to 2 of 2

Macro to export sheets as PDF and name them.

Threaded View

taylorsm Macro to export sheets as PDF... 02-05-2018, 10:49 AM
p24leclerc Re: Macro to export sheets as... 02-05-2018, 10:48 PM
  1. #1
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Macro to export sheets as PDF and name them.

    Sheet 1 is a list of filenames. Then I have 150 sheets that are unique and contain a unique # in Column A. This unique ID# is also in the filename on sheet 1. I need to match those and export that sheet with that filename. I have something similar, but due to a system change, my format has become different and the macro no longer works. I'm hoping that the hard part is done and someone might be able to adjust this macro to fit the current format. The ID# will also be in the sheet name. Sheet names will be "Note_123456" or if duplicates exist, which should not happen, it would be 'Note_123456_1"


    Option Explicit
    
    Sub ED5ExportNotepadPDFFilename()
    Dim wsLIST As Worksheet, ws As Worksheet, fPATH As String, Errors As Boolean
    Dim fileLIST As Range, Fname As Range, myArr As Variant
    
    Application.ScreenUpdating = False
    
    With Application.FileDialog(msoFileDialogFolderPicker)
        .AllowMultiSelect = False
        .InitialFileName = ActiveWorkbook.Path
        .Show
        If .SelectedItems.Count > 0 Then
            fPATH = .SelectedItems(1) & "\"
        Else
            MsgBox "No destination selected, aborting..."
            Exit Sub
        End If
    End With
    Set wsLIST = ActiveWorkbook.ActiveSheet
    Set fileLIST = wsLIST.Range("A:A").SpecialCells(xlConstants)
    fileLIST.Offset(, 1).ClearContents
    
    For Each Fname In fileLIST
        myArr = Split(Fname.Value, ", ")
        For Each ws In ActiveWorkbook.Worksheets
            If InStr(ws.Range("A1"), myArr(2)) > 0 Then
                If InStr(ws.Range("B1"), myArr(0)) > 0 Then
                    If InStr(ws.Range("B1"), myArr(1)) > 0 Then
    'If error, check length of folder/file name path
                        ws.ExportAsFixedFormat _
                            Type:=xlTypePDF, _
                            Filename:=fPATH & Fname.Value & ".pdf", _
                            Quality:=xlQualityStandard, _
                            IncludeDocProperties:=True, _
                            IgnorePrintAreas:=False, _
                            OpenAfterPublish:=False
                        Fname.Offset(, 1).Value = "exported"
                        Exit For
                    End If
                End If
            End If
            If ws.Index = ActiveWorkbook.Sheets.Count Then
                Fname.Offset(, 1).Value = "NOT FOUND"
                Errors = True
            End If
        Next ws
    Next Fname
    
    
    
    Columns("B:B").EntireColumn.AutoFit
        Columns("B:B").Select
        ActiveWorkbook.ActiveSheet.Sort.SortFields.Clear
        ActiveWorkbook.ActiveSheet.Sort.SortFields.Add Key:=Range("B1"), _
            SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
        With ActiveWorkbook.ActiveSheet.Sort
            .SetRange Range("A2:B219")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    If Errors Then MsgBox "Not all filenames/sheets were matched. See FILENAMES column B"
    
    Application.ScreenUpdating = True
    
    End Sub
    Attached Files Attached Files
    Last edited by taylorsm; 02-05-2018 at 10:51 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. VBA to Export Selection of sheets. But only the values of the sheets??!
    By igullage in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-07-2015, 10:41 PM
  2. Export Sheets as PDF macro
    By dd510 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-11-2014, 11:55 AM
  3. Export selected sheets to PDF with a macro
    By dav1b in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-30-2014, 02:26 AM
  4. [SOLVED] A macro with several command buttons that export several sheets (seperately).
    By rimshot609 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-03-2014, 01:30 PM
  5. I would need a macro to export data from base example workbook to export worbook
    By slato8 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-01-2012, 11:21 AM
  6. Macro to use time stamp from two differnt sheets and export row #
    By jblewis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-01-2010, 01:36 PM
  7. Macro to export multiple sheets at one time
    By swilliams in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-26-2010, 12:09 PM

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