+ Reply to Thread
Results 1 to 6 of 6

Need Help with VBA to run vba code on closed wb from active sheet

  1. #1
    Forum Contributor
    Join Date
    07-21-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007,2010,2016
    Posts
    695

    Need Help with VBA to run vba code on closed wb from active sheet

    Dear Experts

    I have xl workbook with vba code i want those macro from another workbook to closed workbook

    I have Macro A,B,C,D,E...in closed workbook saved in path location. i want run these code from open workbook without open closed workbook

    please find the attachment
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,618

    Re: Need Help with VBA to run vba code on closed wb from active sheet

    While you can rather easily access the content of cells of closed workbook, it's not that easy to get to the code, and make it running.

    Why are you thinking of such strange approach?
    May be your macros could be stored in Personal Macro Workbook? Then they could be used in any open workbook.
    Best Regards,

    Kaper

  3. #3
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,151

    Re: Need Help with VBA to run vba code on closed wb from active sheet

    Quote Originally Posted by breadwinner View Post
    ...I have Macro A,B,C,D,E...in closed workbook ... i want run these code from open workbook without open closed workbook
    There is no way to run macros from an "unopened", closed workbook. The reason for this is that for any macro to work, Excel must first have an working, appropriate programming environment for scripts containing some code. This environment is created and launched when you open a given workbook, and you agree to run macros. In a closed workbook, this is "inactive".

  4. #4
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Need Help with VBA to run vba code on closed wb from active sheet

    Hello. They already explained to him that -yes or yes- the book that contains the macros has to be open.
    The well-known "Solver" works like this: it's open... But you don't know it!

    Then, if you want that book to go unnoticed, you can -temporarily- define it as Addin, run its macros and finally close it without saving variations in said hidden book like so:

    PHP Code: 
    Private Sub CommandButton1_Click()
    Rem --------------------\
    Rem I open it and define it as Addin:
    Dim wb As Workbook
    Application
    .ScreenUpdating False
    Set wb 
    Workbooks.Open(ThisWorkbook.Path "\ClosedWb.xlsm", ReadOnly:=True)
    wb.IsAddin True

    Rem 
    --------------------\
    Rem I run one of their macros:
    Run "'" wb.Name "'!A"

    Rem --------------------\
    Rem And I close it without changes:
    wb.Close False
    End Sub 

  5. #5
    Forum Contributor
    Join Date
    07-21-2011
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007,2010,2016
    Posts
    695

    Re: Need Help with VBA to run vba code on closed wb from active sheet

    Hi Boss Thanks for Code i want run code on closedwb get result in closedwb only not openwb pls help

  6. #6
    Valued Forum Contributor
    Join Date
    08-08-2022
    Location
    Buenos Aires
    MS-Off Ver
    Excel 2019
    Posts
    1,777

    Re: Need Help with VBA to run vba code on closed wb from active sheet

    Quote Originally Posted by breadwinner View Post
    Hi Boss Thanks for Code i want run code on closedwb get result in closedwb only not openwb pls help
    It keeps everything I've been through.
    But if you want to modify cells in the hidden workbook or take data from the hidden workbook, whatever you have programmed in 'A' must reference itself.

    If you want us to expand on the idea, then you should upload workbooks to the Forum that reflect a more realistic situation.

+ 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. Adding active rows from sheet to closed database-workbook
    By psjpsjpsjpsj in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-13-2017, 02:54 PM
  2. [SOLVED] vba code to copy a specific sheet from a closed workbook to the active workbook
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2017, 03:09 AM
  3. [SOLVED] vba code from closed workbook to update active sheet not working as requested
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2017, 09:35 AM
  4. [SOLVED] macro to copy specifc sheet in closed workbook to the active sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2017, 09:53 AM
  5. [SOLVED] macro to copy active sheet to a closed workbook in a specified directory
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2017, 04:43 AM
  6. VBA to import all sheets from closed workbook to Active Sheet.
    By shiva_reshs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2014, 02:42 PM
  7. Code to Read/Copy Data from Closed Wb and Return/Paste in Active Wb
    By AlvaroSiza in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2010, 09:26 PM

Tags for this Thread

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