+ Reply to Thread
Results 1 to 4 of 4

Using a userform of a different file (VBA project)

  1. #1
    Registered User
    Join Date
    12-09-2017
    Location
    Israel
    MS-Off Ver
    Office Excel 2007
    Posts
    42

    Using a userform of a different file (VBA project)

    Hi all,
    Is it possible to 'remotely' trigger a userform click event after the userform has loaded?

    I have two separate excel files: file 'A.xlsb' and 'B.xlsm', each has a userform, 'a' and 'b' respectively.

    File 'A' has a shape in Sheet1 that loads userform 'a'.
    File 'B' has a shape in Sheet1 that loads userform 'b'.

    Here is where I'm at:
    When I click the shape in file 'A', userform 'a' is loaded. In it I click a button that loads userform 'b', using Run method, but I cannot get the click event of a button in userform 'b' to work (I don't know how). However I have noticed that if I place a msgbox line after the code that runs the macro to shows userform 'b' (i.e. Run method), the message would only show up AFTER the userform closes. The msgbox appears to suspend as VBA awaits for the line that loaded the form 'b' to 'finalize', and only then go on to the next line of code.

    How then can I both trigger userform 'b', set some params in it (fill it out) and then 'click' on one of its buttons, all programmatically?

    I need to run a few automated form fill outs instead of having to manually fill out form 'b' a dozen times or so.
    (I think I may not even need to show the form itself in order to do that, but I do need the data to go through that form and have a button in it to enter the data to file 'B' 'cause the button does a bunch of stuff with the data before that data is dumped in sheet1 of file 'B'.)

    Thanks!
    Last edited by guyglk; 01-27-2020 at 02:34 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,447

    Re: Using a userform of a different file (VBA project)

    Administrative note
    Please update your profile as necessary to properly reflect the exact version(s) of Excel your question relates to. Members tailor answers based on your Excel version. Your profile does not indicate your version.
    Thanks

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Using a userform of a different file (VBA project)

    Running two userforms in separate workbooks and filling out the userform B from userform A is is programatically tricky.

    You probably do not need the userform B; just its code that does the "thing". It would be far easier to have a macro in B.xlsm that accepts arguments (parameters) and simply call it from A.xlsb.

    Example: put this in B.xlsm Module1
    Please Login or Register  to view this content.
    Run this from A.xlsb Userform A
    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    12-09-2017
    Location
    Israel
    MS-Off Ver
    Office Excel 2007
    Posts
    42

    Re: Using a userform of a different file (VBA project)

    Hi AlphaFrog, thanks for the suggestion! I thinnk it's too complex for me to try and do what I want here (I'm no expert on vba as it is ), also (I did not mention this but.. ) this whole thing needs to be dynamic (not predefined), that it, the userform, the files, they may change and so the controls and other vba components may also be different (the arguments I would need to work with).

    I think it'll simplify things if I just add the necessary form 'a' as part of project 'B', that way talking to form 'b' becomes much easier as I have access to all vba components of the project.

    I would still need to tailor this option for any new file that comes.

    I initially wanted to have a file that would migrate data from one file (old) to anther (new).
    So I would use one external userform (form 'a' in file 'A' ) that would take (export) raw data from one file (let's say file 'X'), fill it out in whatever form I define it to of a second file (form 'b' in file 'B'), and then have that form (b) dump ('import') that data in that second file (B), so basically migrating data from File X to B.
    But I'm bitting off way more than I can chew here
    Last edited by guyglk; 01-28-2020 at 03:06 AM.

+ 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. Userform for Project closing
    By djemy1975* in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2018, 08:11 PM
  2. [SOLVED] Project using Advanced filter, Userform, and Macros
    By LTSSB in forum Excel General
    Replies: 1
    Last Post: 04-17-2018, 02:04 PM
  3. Replies: 3
    Last Post: 08-11-2017, 03:10 AM
  4. Replies: 1
    Last Post: 06-12-2017, 09:20 PM
  5. Copying a userform from one project to another
    By calmena in forum Excel General
    Replies: 5
    Last Post: 03-23-2011, 11:06 AM
  6. Cannot save Project file as MS Access file
    By Jumpinjackflash in forum Excel General
    Replies: 1
    Last Post: 01-11-2006, 07:40 PM
  7. Copying a Userform within the same project
    By needyourhelp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-18-2005, 09:05 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