+ Reply to Thread
Results 1 to 6 of 6

Creating Macro using Active Workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    01-26-2015
    Location
    United States
    MS-Off Ver
    2010 & 2013
    Posts
    24

    Creating Macro using Active Workbook

    I have a macro saved to perform VBA codes but it is a master form that I am saving for several items. Each time I save the Workbook, I have to go in and edit the macro with the new Workbook name. Can someone tell me how to edit the macro so it will work as the active Workbook no matter what the file name is?

    Thank You.

    Sub Hide_All()
    '
    ' Hide_All Macro
    ' Hide all blank lines
    '
    ' Keyboard Shortcut: Ctrl+Shift+H
    '
    Application.Run _
    "'Detail 090-Engineering & Planning FY16.xlsm'!Expense_Hide"
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    Sheets("ACTUAL VARIANCES").Select
    Application.Run _
    "'Detail 090-Engineering & Planning FY16.xlsm'!Actual_Variances"
    Sheets("PER VARIANCES").Select
    Application.Run _
    "'Detail 090-Engineering & Planning FY16.xlsm'!Per_Vairances"
    Sheets("TOTALS").Select
    Application.Run "'Detail 090-Engineering & Planning FY16.xlsm'!Totals"
    End Sub

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Creating Macro using Active Workbook

    Is code you posted in same workbook as the codes you wish to run with Application.Run?
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Registered User
    Join Date
    01-26-2015
    Location
    United States
    MS-Off Ver
    2010 & 2013
    Posts
    24

    Re: Creating Macro using Active Workbook

    Yes, the codes are saved in each Workbook. I just wanted to see if I could set up so it would use the active workbook instead of specifying the workbook file name each time.

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Creating Macro using Active Workbook

    If code is all in same workbook you do not need name or Run:
    Sub Hide_All()
    '
    ' Hide_All Macro
    ' Hide all blank lines
    '
    ' Keyboard Shortcut: Ctrl+Shift+H
    '
    Call Expense_Hide
    ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
    Sheets("ACTUAL VARIANCES").Select
    Call Actual_Variances
    Sheets("PER VARIANCES").Select
    Call Per_Vairances
    Sheets("TOTALS").Select
    Call Totals
    End Sub

  5. #5
    Registered User
    Join Date
    01-26-2015
    Location
    United States
    MS-Off Ver
    2010 & 2013
    Posts
    24

    Re: Creating Macro using Active Workbook

    That is exactly what I was looking for! Thank you!

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Creating Macro using Active Workbook

    You are welcome. Please mark thread solved using links at top of page.

+ 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. Run Macro in closed workbook and copy specific coloumn in active workbook
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-07-2013, 03:43 AM
  2. Replies: 2
    Last Post: 06-21-2013, 08:59 PM
  3. Save Active workbook, Add a password via a prompt and stop creating backups
    By dlast in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-01-2013, 05:59 AM
  4. VBA macro for hyperlink to active workbook in the active workbook path
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-10-2013, 05:37 AM
  5. Macro to Print active sheet as PDF to Active workbook and customize name
    By Scott Taylor in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-17-2012, 08:52 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