+ Reply to Thread
Results 1 to 8 of 8

How to call Private Sub using Application.Run

Hybrid View

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    How to call Private Sub using Application.Run

    I’m looking for a code to trigger a macro located in a different workbook.
    The current code I’m using is..
    Application.Run ("'Data Lookup.xlsm'!Main")
    Where ‘Main’ is the macro that I want to trigger, looks like ‘Main’ is set up as Public Sub in the ‘Data Lookup’ workbook but there are other Private Sub located… Private Sub Dump(), Private Sub Login(), Private Sub Logout().
    My question is does above Application.Run code trigger all stated Private Sub? If not what code should I use to trigger Public sub and all Private Subs?

    Thanks!

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to call Private Sub using Application.Run

    That code will only run the Main routine (which may or may not run the others). To run a different one, just change the name of the routine in that code.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Re: How to call Private Sub using Application.Run

    I tried calling out one of the Private Sub Dump(), using below code and it gave me an error "Object variable or With block variable not set"

    Application.Run ("'Data Lookup.xlsm'!Main")
    Application.Run ("'Data Lookup.xlsm'!Dump")

  4. #4
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to call Private Sub using Application.Run

    That suggests the error occurred in the Dump routine. Given that it is private, it's presumably not intended to be called externally.

  5. #5
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Re: How to call Private Sub using Application.Run

    So, how can I trigger Dump and other Private Sub() in the 'Data Lookup' workbook, without changing anything to that file?

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to call Private Sub using Application.Run

    That is how you call it. My point is that the routine may not work if called externally.

  7. #7
    Registered User
    Join Date
    09-13-2012
    Location
    GA, USA
    MS-Off Ver
    2010
    Posts
    48

    Re: How to call Private Sub using Application.Run

    That means I cannot trigger any routine called out in Private Sub() and it has to be Public

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to call Private Sub using Application.Run

    No it does not. You can call it but if it is designed to be called only internally (eg depends on some variables being previously set) then it won't necessarily work when called from elsewhere.

+ 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] Using Application.Run to call a private sub in a module from ThisWorkbook object
    By Stormin' in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 10-24-2017, 10:47 AM
  2. Call Macro from Private Sub
    By mgolda87 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-12-2016, 12:32 PM
  3. Call private sub with variable in its name
    By Willardio in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-10-2013, 11:56 AM
  4. Call Private Sub from Add-In
    By Vaw08 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2013, 02:33 PM
  5. call private sub from module
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-13-2009, 10:02 AM
  6. how to call a Private Sub ?
    By dpenny in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-12-2007, 01:15 PM
  7. IF Statements-call private sub
    By CrimsonPlague29 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 05-11-2006, 12:00 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