+ Reply to Thread
Results 1 to 3 of 3

How Do I use Class Modules in Excel VBA

Hybrid View

gauss1976 How Do I use Class Modules in... 01-05-2007, 05:05 AM
jasoncw Regarding your specific... 01-05-2007, 11:20 AM
tony h I suspect it goes with a form... 01-05-2007, 11:56 AM
  1. #1
    Registered User
    Join Date
    07-20-2006
    Posts
    7

    Unhappy How Do I use Class Modules in Excel VBA

    Hi to all,

    I have the following problem: I have found some code on the web regarding the use of automating IE using VBA. However, as far as I understand the code has been written for a Class Module (I think). The code is below
    (I have left the Class name as Class1)

    Option Explicit
    Public WithEvents ie1 As InternetExplorer
    Public ie2 As InternetExplorer
    Private Declare Sub Sleep Lib "kernel32" ( _
    ByVal dwMilliseconds As Long)
    Private Sub Command1_Click()
    Set ie1 = CreateObject("InternetExplorer.Application")
    ie1.Visible = True
    ie1.Navigate2 "http://www.yahoo.com"
    While ie1.ReadyState < READYSTATE_COMPLETE
    Sleep 100
    Debug.Print "ie1 busy"
    Wend
    Debug.Print ie1.LocationURL & "AA"
    ie1.Navigate2 "http://www.google.com", 1
    While ie2.ReadyState < READYSTATE_COMPLETE
    Sleep 100
    Debug.Print "ie2 busy"
    Wend
    Debug.Print ie2.LocationURL & "BB"
    End Sub
    Private Sub ie1_NewWindow2(ppDisp As Object, Cancel As Boolean)
    Set ie2 = CreateObject("InternetExplorer.Application")
    Set ppDisp = ie2.Application
    Debug.Print "NewWindow2"
    End Sub

    My question is: How can I use this code ??

    So far I have tried the following (Set up the code in a standard module)

    Option Explicit
    Dim IEobject As New Class1
    Public Sub Test_Class1()
    Set IEobject1.ie1 = InternetExplorer
    End Sub

    However I get the error:
    Compile Error: Variable not defined

    I am desperate for any help.

    gauss1976

  2. #2
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Regarding your specific error, you declared the variable IEobject, but then you are using IEobject1 in your code. These are not the same variables.

  3. #3
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187
    I suspect it goes with a form :_ Private Sub Command1_Click()

    The IEobject1 is not declared anywhere.

    Where did you get the code from - there should be more info.

    It may also need some references to be made.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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