+ Reply to Thread
Results 1 to 6 of 6

Making a macro that runs other macros

Hybrid View

  1. #1
    Registered User
    Join Date
    10-13-2014
    Location
    Phoenix, AZ
    MS-Off Ver
    2010
    Posts
    99

    Making a macro that runs other macros

    Hello,
    I have Excel 2010 and I have a macro on each of six sheets in a workbook. The macro exports the contents of the sheet to a PDF file with a designated name and file location. The issue I'm having is that to get to each sheet to run each macro I have to go to a welcome screen, select a user name, and enter their password and then run the macro on that screen. This is time consuming and inelegant. I need another macro on the welcome screen which I can click to run all of the other macros. I thought about running another macro to go through each of the steps above but its far too much work for too little payoff.

    Here is the code which resulted from each of the macro record sessions.

    Sub Amy_ExceltoPDF()
     '
     ' Amy_ExceltoPDF Macro
     '
     ' Keyboard Shortcut: Ctrl+Shift+J
     '
     ChDir "V:\Arizona CSRs\Dashboard\Team PDFs"
     ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     "V:\Arizona CSRs\Dashboard\Team PDFs\Amy.pdf", Quality:=xlQualityStandard, _
     IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
     True
     End Sub 
    
    Sub Chad_ExcelToPDF()
     '
     ' Chad_ExcelToPDF Macro
     '
     ' Keyboard Shortcut: Ctrl+Shift+L
     '
     ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     "V:\Arizona CSRs\Dashboard\Team PDFs\Chad.pdf", Quality:=xlQualityStandard, _
     IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
     True
     End Sub 
    
    Sub David_ExcelToPDF()
     '
     ' David_ExcelToPDF Macro
     '
     ' Keyboard Shortcut: Ctrl+Shift+M
     '
     ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     "V:\Arizona CSRs\Dashboard\Team PDFs\David.pdf", Quality:=xlQualityStandard, _
     IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
     True
     End Sub 
    
    Sub Danielle_ExcelToPDF()
     '
     ' Danielle_ExcelToPDF Macro
     '
     ' Keyboard Shortcut: Ctrl+Shift+G
     '
     ChDir "V:\Arizona CSRs\Dashboard\Team PDFs"
     ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     "V:\Arizona CSRs\Dashboard\Team PDFs\Danielle.pdf", Quality:= _
     xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
     OpenAfterPublish:=True
     End Sub 
    
    Sub Brianna_ExcelToPDF()
     '
     ' Brianna_ExcelToPDF Macro
     '
     ' Keyboard Shortcut: Ctrl+Shift+A
     '
     ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     "V:\Arizona CSRs\Dashboard\Team PDFs\Brianna.pdf", Quality:=xlQualityStandard _
     , IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True
     End Sub
     
    Sub Rachel_ExcelToPDF()
     '
     ' Rachel_ExcelToPDF Macro
     '
     ' Keyboard Shortcut: Ctrl+Shift+B
     '
     ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
     "V:\Arizona CSRs\Dashboard\Team PDFs\Rachel.pdf", Quality:=xlQualityStandard _
     , IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= True
     End Sub 
    Last edited by JBeaucaire; 10-31-2014 at 03:14 PM. Reason: Added missing CODE tags. Please read and follow the Forum Rules, link above in the menu bar. Thanks.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Making a macro that runs other macros

    Hi worthm

    Assign to a Button
    Option Explicit
    
    Sub Print_All()
      Call Amy_ExceltoPDF
      Call David_ExceltoPDF
      Call Danielle_ExceltoPDF
      Call Brianna_ExceltoPDF
      Call Rachel_ExceltoPDF
      Call Chad_ExceltoPDF
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    10-13-2014
    Location
    Phoenix, AZ
    MS-Off Ver
    2010
    Posts
    99

    Re: Making a macro that runs other macros

    That's a very elegant solution but the button is on a welcome screen and when the macro runs it creates PDF pictures of the welcome screen rather than the correct screen for each tab. How do I correct? I think I need some kind of activate.sheet or select.sheet but Im not a programmer

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Making a macro that runs other macros

    Hi worthm

    What are the Sheet Names? Are they in the same Workbook as the Welcome Screen?

  5. #5
    Registered User
    Join Date
    10-13-2014
    Location
    Phoenix, AZ
    MS-Off Ver
    2010
    Posts
    99

    Re: Making a macro that runs other macros

    Hello
    All of the sheets are in the same workbook as the welcome screen. The welcome screen is called "welcome screen". The rest are named "Amy", "Chad", "David", "Danielle", "Rachel", and "Brianna". All without the ""s
    Thank you!

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Making a macro that runs other macros

    Hi worthm

    Not tested
    Option Explicit
    Private Sub CommandButton1_Click()  '<---Rename as appropriate
      Dim myPath As String, FileName As String
      Dim sht As Worksheet
      Dim wrk As Workbook
      Set wrk = ThisWorkbook
      myPath = "V:\Arizona CSRs\Dashboard\Team PDFs\"  '<---Save the PDF here
      For Each sht In wrk.Worksheets
        'Execute on every sheet except the Welcome Screen
        If sht.Name <> "welcome screen" Then '<---Skip this Worksheet
          FileName = sht.Name & ".Pdf"   '<---Name the PDF
          sht.ExportAsFixedFormat Type:=xlTypePDF, FileName:=myPath & FileName, Quality _
                    :=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
                    OpenAfterPublish:=False
        End If
      Next sht
    End Sub

+ 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] Macro Ignores If Statements and Runs Both Macros
    By EnigmaMatter in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-19-2014, 09:18 AM
  2. [SOLVED] What goes between 2 macros so one runs right after the first?
    By ILoveStMartin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2012, 01:34 AM
  3. Excel runs really slow after macros. help!!
    By excelnoobie123 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-09-2010, 04:35 AM
  4. Unprotect only certain cells after macros runs to unhide range of
    By MiComputerGeek78 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-13-2006, 12:50 PM
  5. How to stop other macros while current macro runs
    By Paul987 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-24-2006, 12:20 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