+ Reply to Thread
Results 1 to 6 of 6

Macro to PDF multiple tabs and save in same file as the template is saved in

Hybrid View

  1. #1
    Registered User
    Join Date
    05-17-2018
    Location
    Denver, CO, US
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Macro to PDF multiple tabs and save in same file as the template is saved in

    I have used a macro to PDF a tab which allows the PDF to be saved in whichever folder I need it to be. However, it doesn't contain a code that spells out which tabs that need to be a PDF. Can anyone provide a code that can do both? Essentially, I have a template that gets re-saved to several client files during the day and when they pdf a certain selection of tabs this PDF needs to be saved in the same place as the re-saved excel spreadsheet. In addition, I'd like the PDF to reflect the same name as the excel file.

  2. #2
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Macro to PDF multiple tabs and save in same file as the template is saved in

    please provide the code that you are using currently.

    we can add one to few line to do what you request.

    *remember to surround your code with or click # in the format option.

  3. #3
    Registered User
    Join Date
    05-17-2018
    Location
    Denver, CO, US
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Re: Macro to PDF multiple tabs and save in same file as the template is saved in

    I have tried to post the code by I receive this error: "You are not allowed to post any kinds of links, images or videos until you post a few times."

    I also began and ended the post with pressing the # format button to produce code "" like you suggested.

  4. #4
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Macro to PDF multiple tabs and save in same file as the template is saved in

    sorry is "[ CODE ]your code[ /CODE ]"(without space) instead. post#2 is autohide it...

    you may upload workbook (that contain the code and replace sensitive data with dummy data) through :
    go advanced > management attachment > upload

  5. #5
    Registered User
    Join Date
    05-17-2018
    Location
    Denver, CO, US
    MS-Off Ver
    MS Office 2013
    Posts
    3

    Re: Macro to PDF multiple tabs and save in same file as the template is saved in

    I have uploaded my spreadsheet via manage attachments. It is called "PDF Macro Example Code."

    Thanks!
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    03-22-2017
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    230

    Re: Macro to PDF multiple tabs and save in same file as the template is saved in

    Try this, it should fit your need.

    However, there have some different.
    1. final message box will have some different.
    2. another message box will incur if cancel overwrite. to ask you whether to continue to next tab.

    please let me know if you need further amendment.
    Option Explicit
    Sub Apdf()
    Dim wsA As Worksheet
    Dim wbA As Workbook
    Dim strName As String
    Dim strPath As String
    Dim strFile As String
    Dim strPathFile As String
    Dim myFile As Variant
    Dim lOver As Long
    Dim Counter, TotalSht As Integer
    Dim answer As String
    Counter = 0
    On Error Resume Next
    
    Set wbA = ActiveWorkbook
    TotalSht = wbA.Worksheets.Count
    'get active workbook folder, if saved
    strPath = wbA.Path
    If strPath = "" Then
      strPath = Application.DefaultFilePath
    End If
    strPath = strPath & "\"
    
    For Each wsA In wbA.Worksheets
      strName = wsA.Range("A1").Value _
                & " - " & wsA.Range("A2").Value _
                & " - " & wsA.Range("A3").Value
    
    'create default name for savng file
      strFile = strName & ".pdf"
      strPathFile = strPath & strFile
    
      If bFileExists(strPathFile) Then
        lOver = MsgBox("Overwrite existing file?", _
          vbQuestion + vbYesNo, "File Exists")
        If lOver <> vbYes Then
          'user can enter name and
          ' select folder for file
          myFile = Application.GetSaveAsFilename _
              (InitialFileName:=strPathFile, _
                  FileFilter:="PDF Files (*.pdf), *.pdf", _
                  title:="Select Folder and FileName to save")
          If myFile <> "False" Then
            strPathFile = myFile
          Else
            answer = MsgBox("This save has canceled." & vbNewLine _
            & "Continue to next tab?", vbOKCancel, "File to Save")
            If answer = vbCancel Then
              GoTo Summary
            Else
              GoTo Bottom
            End If
          End If
        End If
      End If
      'export to PDF in current folder
        wsA.ExportAsFixedFormat _
            Type:=xlTypePDF, _
            Filename:=strPathFile, _
            Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, _
            OpenAfterPublish:=False
        Counter = Counter + 1
    Bottom:
    Next
    'confirmation message with file info
    Summary:
        MsgBox Counter & "/" & TotalSht & " PDF file(s) has been created at: " _
          & vbCrLf & strPath
    End Sub
    '=============================
    Function bFileExists(rsFullPath As String) As Boolean
      bFileExists = CBool(Len(Dir$(rsFullPath)) > 0)
    End Function
    '=============================
    Hope you can learn every time you visit here.

    If you still confuse on how it work, kindly ask or go to
    i) Formula - Formula (Ribbon) > Formula Auditing (Section) > Evaluate Formula > Evaluate; or
    ii) VBA/Code - Click F8 to see how it work step by step.

    It it take care of your question, Please:
    Mark tread as [Solved] [Thread Tools->Mark thread as Solved]
    ;and
    Click *Add Reputation to thank anyone solved your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Save as Macro - Can't find file once saved?
    By Dibbley247 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-30-2014, 08:03 PM
  2. Save Macro Template on a network drive as Excel file using a cell value as the name
    By rjagain62 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-26-2014, 03:21 PM
  3. Macro to extract a tab from one file, add it to a master template file and then save as
    By SweetSorcery in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-03-2014, 11:36 AM
  4. [SOLVED] looper to copy tabs of a data file into template and save as
    By amartin575 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 02-26-2014, 10:47 AM
  5. [SOLVED] Why not always save a template file in the Macro-Enabled format?
    By alice2011 in forum Excel General
    Replies: 2
    Last Post: 01-17-2014, 06:15 AM
  6. Replies: 2
    Last Post: 05-06-2013, 06:41 PM
  7. Macro to save changes from dotm template to new docx file
    By Pius in forum Word Formatting & General
    Replies: 1
    Last Post: 01-30-2013, 03:02 AM

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