+ Reply to Thread
Results 1 to 22 of 22

open user Form in workbook1 from workbook2

  1. #1
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    open user Form in workbook1 from workbook2

    Basically I have a user form that opens up another workbook file. and then hide the user form. Now what I owuld like to do is have a button on the worksheet that will recall the userform and close the workbook.

    The user form is frmUsreDataSheet It is in VBAProject(UserformExample.xlsm)

    The file or workbook that gets opened is VBAProject(FSO Open Report.xlsx)

    I searched the web and there seems to be a lot of conflict about whether it can be done. Some suggestion you create a reference in the FBAProject that houses the userform, and then create a code that references or something like that.

    Help Please.

    Thanks.

    Oh and not sure if I should be using an Activex button or a form control button. but the button will exist on the worksheet.

  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: open user Form in workbook1 from workbook2

    Your button may simply call the routine in the userform workbook that shows that userform, using Application.Run. No reference will be required.
    • 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
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    Ok Izandol here is the code I came up with, but it doesn't work.

    Private Sub CommandButton2_Click()
    Application.Run " btnOpenDatasheetMenu_Click()frmUsrDataSheet.Show "
    End Sub

    obviously something is wrong.

  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: open user Form in workbook1 from workbook2

    In which module is btnOpenDatasheetMenu_Click routine?

  5. #5
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    Quote Originally Posted by Izandol View Post
    In which module is btnOpenDatasheetMenu_Click routine?
    It is in UserformExample.xlsm

  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: open user Form in workbook1 from workbook2

    Which module (Module1, or worksheet module, or...?), not which workbook?

  7. #7
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    Quote Originally Posted by Izandol View Post
    Which module (Module1, or worksheet module, or...?), not which workbook?
    It's not in any module.. I'm sorry but i click on everything in the VBa the code does not exist in a module it exist within the form..

    I attached a picture of the vba with the code for that button opened.
    Attached Images Attached Images

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

    Re: open user Form in workbook1 from workbook2

    Then you must create routine in normal module like:
    Please Login or Register  to view this content.
    then you may use:
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    I found these instruction for running code in another workbook, but I do not know where the application.run is located.


    Go to the workbook that holds the routine you want to run and note the exact name of the macro/function, and any arguements required.
    Copy the appropriate sub above.
    In the Workbook that you want to trigger your macro from (not the one that holds the code you want to execute)...
    In Excel press Alt + F11 to enter the VBE.
    Press Ctrl + R to show the Project Explorer.
    Right-click desired file on left (in bold).
    Choose Insert -> Module.
    Paste code into the right pane.
    Modify the NameOfFile and PathToFile variables to the appropriate workbook name and path of the file that holds the code you want to run.
    Update the Application.run line to list your target macro's name, and arguments (If necessary.)
    Press Alt + Q to close the VBE.
    Save workbook before any other changes.

  10. #10
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    Ok Izandal I can create the module like you suggested, and are you saying to put the application.run code into the buttonclick command?

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

    Re: open user Form in workbook1 from workbook2

    Yes that is correct.

  12. #12
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    Ok I put the code into new module in thworkbook where the fomr exist, then I put the application.run code into the command button in the workbook where the button exist.

    Now I am getting the following error run time error 1004 Method "Run" of object"_Application" failed.

  13. #13
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    I click the debug on the error code. I attached a picture of the code it highlighted.

    It highlighted the application.run code...
    Attached Images Attached Images

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

    Re: open user Form in workbook1 from workbook2

    Is userformexample workbook open? It does not look like it is.

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

    Re: open user Form in workbook1 from workbook2

    What is code to open other workbook? Will it be OK to allow user to close this workbook and then have userform reappear automatically?

  16. #16
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    How would it know "when" to reappear? Because the user will be working in the workbook or worksheet and when they are finished they would click button to get back to form. So how would VBA/Windows/Excel know when that is?

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

    Re: open user Form in workbook1 from workbook2

    By monitoring the events of the workbook. For example:
    Please Login or Register  to view this content.
    Or you may use button.
    Last edited by Izandol; 02-07-2014 at 12:42 PM.

  18. #18
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    Not sure how that would work.. How owuld it know when to open the form?

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

    Re: open user Form in workbook1 from workbook2

    Please see example I added.

  20. #20
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    Quote Originally Posted by Izandol View Post
    Then you must create routine in normal module like:
    Please Login or Register  to view this content.
    then you may use:
    Please Login or Register  to view this content.
    Ok I just noticed in the error it has the following path ..c:\users\ddempsey\Documents\userformexample.xlsm.. This is not the correct path, why is it looking here for the form.

    The form is in the following path. C:\Users\ddempsey\Desktop\notes

    should i move it to the path noted in the error?

  21. #21
    Registered User
    Join Date
    06-30-2010
    Location
    Newport New VA
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: open user Form in workbook1 from workbook2

    It worked when i changed the path to the path in the error box. Oh well this is close enough. I'm going to close this discussion. Its getting too long.

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

    Re: open user Form in workbook1 from workbook2

    No - the workbook should be open - is it not?

+ 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. How to bring data from workbook1 to workbook2 by comparing values of workbook2
    By amethystfeb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-04-2013, 09:38 AM
  2. Workbook1 should start Workbook2
    By KausBorealis in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-03-2012, 10:52 PM
  3. Move tab from Workbook1 to Workbook2 using Macro VBA
    By nachousa in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-08-2010, 11:58 AM
  4. Data from workbook1 to workbook2 every week but in different place in workbook2
    By cheelie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2007, 06:26 PM
  5. Replies: 1
    Last Post: 05-18-2005, 09:06 AM

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