+ Reply to Thread
Results 1 to 10 of 10

Must open and close UserForm twice for the other codes in the "Open..." Macro to execute

  1. #1
    Forum Contributor
    Join Date
    09-20-2012
    Location
    Norge
    MS-Off Ver
    Excel 2007
    Posts
    114

    Must open and close UserForm twice for the other codes in the "Open..." Macro to execute

    Hello,

    I have the following issue:

    Whenever I open the UserForm1 it does not execute all the codes except for the code that actually makes it Show. I found that everytime I open it I have to close it again and then re-open it for the codes to actually execute.

    The following code is what I´m currently using:

    Please Login or Register  to view this content.

    I´m thinking maybe there should be an ApplicationEvent or something in the beginning of the code?

    Thanks in advance

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Must open and close UserForm twice for the other codes in the "Open..." Macro to execu

    Hi, tnuis,

    if it´s a UserForm in VBA I´d expect you to use UserForm_Initialize or UserForm_Activate (behind the UserForm) instead of UserForm_Open (which isn´t present in my UserForm in VBA).

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Contributor
    Join Date
    09-20-2012
    Location
    Norge
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: Must open and close UserForm twice for the other codes in the "Open..." Macro to execu

    Quote Originally Posted by HaHoBe View Post
    Hi, tnuis,

    if it´s a UserForm in VBA I´d expect you to use UserForm_Initialize or UserForm_Activate (behind the UserForm) instead of UserForm_Open (which isn´t present in my UserForm in VBA).

    Ciao,
    Holger
    Hi HaHoBe,

    I tried both UserForm1_Activate and also UserForm1_Initialize but both of them give me the same result. I still have to close and click the Macro Button twice for the codes to run

    Any other suggestions?

  4. #4
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Must open and close UserForm twice for the other codes in the "Open..." Macro to execu

    Hello tnuis,

    I agree with HaHoBe. You may also want to select, Microsoft Visual Basic for Applications Extensibility 5.3

    in the VBE under the Tools>References menu.

    Regards
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  5. #5
    Forum Contributor
    Join Date
    09-20-2012
    Location
    Norge
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: Must open and close UserForm twice for the other codes in the "Open..." Macro to execu

    Quote Originally Posted by Winon View Post
    Hello tnuis,

    I agree with HaHoBe. You may also want to select, Microsoft Visual Basic for Applications Extensibility 5.3

    in the VBE under the Tools>References menu.

    Regards

    Hi Winon,

    I would also agree With HaHoBe but the only problem is that it makes no difference. I´m still stuck With the same problem. I selected the Microsoft Visual Basic for Applications Extensibility 5.3 like you said......Why did you want me to do this? What difference is this supposed to make? Am I supposed to doe anything else aswell?
    It is still not working I´m afraid.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644
    Its Userform_Initialize not <formname>_Initialize.

    Same for Activate.
    If posting code please use code tags, see here.

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Must open and close UserForm twice for the other codes in the "Open..." Macro to execu

    Please Login or Register  to view this content.
    The .Show will suspend execution. when you close the userform the information is then loaded. Because they is no code to unload from memory second time around the userform shows with values.
    Cheers
    Andy
    www.andypope.info

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Must open and close UserForm twice for the other codes in the "Open..." Macro to execu

    Hi, tnuis,

    there is only one Initialize-Event as well as one Activate-Event for each userform, and they all have the very same names as Norie stated: UserForm_xxx, nothing else.

    Thanks, Andy, for the passing the information, I had missed the latter part of the code and certainly would not figured it out.

    Ciao,
    Holger

  9. #9
    Forum Contributor
    Join Date
    09-20-2012
    Location
    Norge
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: Must open and close UserForm twice for the other codes in the "Open..." Macro to execu

    Quote Originally Posted by Andy Pope View Post
    Please Login or Register  to view this content.
    The .Show will suspend execution. when you close the userform the information is then loaded. Because they is no code to unload from memory second time around the userform shows with values.


    Thank you so much Andy, that simple little thing did the trick

    I see what you are saying. Will look out for that in the future. Learning something New everyday, love it

  10. #10
    Forum Contributor
    Join Date
    09-20-2012
    Location
    Norge
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: Must open and close UserForm twice for the other codes in the "Open..." Macro to execu

    Quote Originally Posted by HaHoBe View Post
    Hi, tnuis,

    there is only one Initialize-Event as well as one Activate-Event for each userform, and they all have the very same names as Norie stated: UserForm_xxx, nothing else.

    Thanks, Andy, for the passing the information, I had missed the latter part of the code and certainly would not figured it out.

    Ciao,
    Holger
    Ok thanks for the heads up HaHoBe

+ 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. need VBA code to open a file type then do a "=countA(A:A)-1" and close it
    By BrandonFromSingapore in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-26-2012, 12:19 PM
  2. how to close a file opened with "Workbooks.Open Filename:=sWb"
    By ggremel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-07-2011, 10:37 PM
  3. [SOLVED] Loop through ".DAT" files, open run code, close next
    By Les Stout in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-20-2006, 05:20 AM
  4. How do I Make a macro in exel to just open the "open" screen?
    By JackSchilder in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-04-2006, 08:51 AM
  5. Replies: 0
    Last Post: 01-04-2006, 06:55 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