+ Reply to Thread
Results 1 to 12 of 12

Running a Class Module from a Button

  1. #1
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Running a Class Module from a Button

    Hello,

    I am new to class modules and I'm trying to figure out how to run it. I am trying to use WithEvents and NewWindow2 to access a child window. WithEvents is only available in an object module, so I created a class module and added the following code:

    Please Login or Register  to view this content.
    I then created a command button on Sheet1, however when I click the button nothing happens. I have attached a workbook with this example.

    Thanks in advance,
    Matt
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Running a Class Module from a Button

    Matt

    The code for the command button doesn't go in the class module, well not that one anyway.

    It goes in the Sheet1's module.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Running a Class Module from a Button

    Thanks for the reply. I moved the code to Sheet1's module, and it does run when I click the command button, but I get an error with:

    Please Login or Register  to view this content.
    The error I get is "Object variable or With block variable not set", any idea as to why?

    Thanks,
    Matt

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Running a Class Module from a Button

    You have IE2 set to nothing. It won't have a method or property.
    Please Login or Register  to view this content.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Running a Class Module from a Button

    What's the name of the class?

  6. #6
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Running a Class Module from a Button

    Thanks Solus, but the other Sub in the code sets IE2 as New InternetExplorer once it is created:

    Please Login or Register  to view this content.
    However, even if I remove "Set IE2 = Nothing" I still get the same error.

    Thanks,
    Matt

  7. #7
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Running a Class Module from a Button

    Hi Norie,

    The entire code is listed in my first post. I moved it into the Sheet1 module as you suggested and deleted the class module, which allows it to run, however, I don't believe the second Sub that sets IE2 is running:

    Please Login or Register  to view this content.
    I added a message box to the IE1_NewWindow2 Sub, just to see it it was firing, and it was not.

    I found this method of WithEvents and NewWindow2 from the following websites:

    http://www.mrexcel.com/forum/excel-q...ld-window.html

    http://visualbasic.about.com/od/stan...ieinstance.htm

    Thanks,
    Matt

  8. #8
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Running a Class Module from a Button

    I believe my original question of how to run my code has been answered. My issue is now more in line with my other thread of using VBA to interact with a Child Window in IE8: http://www.excelforum.com/excel-prog...ow-in-ie8.html

    So I am going to mark this thread as solved, thanks for the help.
    Matt

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Running a Class Module from a Button

    Matt

    If the code is now working then you should have a reference to the child window, IE2.

    You should be able to interact with that in the same way you would any other instance of IE.

  10. #10
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Running a Class Module from a Button

    Hi Norie,

    The problem I now have is that the second sub is not firing:

    Please Login or Register  to view this content.
    Since this doesnt fire, IE2 is not set, and an error occurs when trying to interact with IE2

    In my other thread, about interacting with a child window:

    http://www.excelforum.com/excel-prog...ow-in-ie8.html

    The forum user Chippy thinks the problem is that the WithEvents/NewWindow2 method is not working because it relates to IE browser windows. He believes the child window I am trying to access is a dynamic HTML/Javascript/AJAX window which is inside an iframe. Unfortunately he was unsure how to reslove this problem, so the issue remains. I just didn't want to have two active threads with the same question.

    Thanks,
    Matt

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Running a Class Module from a Button

    Matt

    Is the URL in your original post 'real'?

  12. #12
    Registered User
    Join Date
    11-06-2013
    Location
    North Carolina
    MS-Off Ver
    Excel 2010
    Posts
    19

    Re: Running a Class Module from a Button

    Yes. The webpage is shows an example of a RadWindow. I thought it was just a IE browser window within a window, but apparently it is something completely different.

+ 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] ComboBox class .AddItem filled in class module
    By Jacques Grobler in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-03-2012, 05:48 AM
  2. Replies: 1
    Last Post: 08-30-2011, 02:23 AM
  3. class module?
    By sybmathics in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 02-25-2006, 10:35 AM
  4. Class Module
    By Bill Martin in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-25-2006, 05:00 PM
  5. Class module
    By Avner Mediouni in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-19-2005, 11:06 AM

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