Question : Control Opera From VBA Macro

I'm trying to use VBA to open a web page in Opera browser and fill in two fields.
Problem is there is no Opera.application class like IE (InternetExplorer.Application)
Is there anyway to remotly control Opera using VBA?
I believe that I must use VBA because this macro must run inside of an Excel Spreadsheet.

Private Sub OpenSite(ByVal UserID As String, ByVal UserPW As String)
On Error Resume Next

    Dim ie As Object
    Set ie = CreateObject("Opera.application")
    ie.Visible = True
    ie.Navigate ("https://somewebpage.com/login.asp")
    Do
        If ie.readyState = 4 Then
            ie.Visible = True
            Exit Do
        Else
            DoEvents
        End If
    Loop
   
    ie.document.Form.UserID.Value = UserID
    ie.document.Form.UserPW.Value = UserPW
    Set ie = Nothing
End Sub

Answer : Control Opera From VBA Macro

Here's an example of how to "wire up" ALL 72 TextBoxes to the same event handler at run-time so you don't have to manually create 72 different handlers in the IDE.

Also included are examples of how to implement Left, Right, Up and Down buttons:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
Public Class Form1

    Private LastTextBox As TextBox = Nothing

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim tb As TextBox
        Dim ctls() As Control
        For i As Integer = 0 To 71
            ctls = Me.Controls.Find("TextBox" & i, True)
            If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
                tb = CType(ctls(0), TextBox)
                AddHandler tb.GotFocus, AddressOf tb_GotFocus
            End If
        Next
    End Sub

    Private Sub tb_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim tb As TextBox = CType(sender, TextBox)
        LastTextBox = tb
    End Sub

    Private Sub btnRight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRight.Click
        If Not IsNothing(LastTextBox) Then
            Dim i As Integer
            Dim strInt As String = LastTextBox.Name.Remove(0, "TextBox".Length)
            If Integer.TryParse(strInt, i) Then
                If ((i + 1) Mod 9) <> 0 Then
                    i = i + 1
                    Dim ctls() As Control = Me.Controls.Find("TextBox" & i, True)
                    If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
                        Dim tb As TextBox = CType(ctls(0), TextBox)
                        tb.Focus()
                    End If
                Else
                    LastTextBox.Focus()
                End If
            End If
        End If
    End Sub

    Private Sub btnLeft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeft.Click
        If Not IsNothing(LastTextBox) Then
            Dim i As Integer
            Dim strInt As String = LastTextBox.Name.Remove(0, "TextBox".Length)
            If Integer.TryParse(strInt, i) Then
                If (i Mod 9) <> 0 Then
                    i = i - 1
                    Dim ctls() As Control = Me.Controls.Find("TextBox" & i, True)
                    If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
                        Dim tb As TextBox = CType(ctls(0), TextBox)
                        tb.Focus()
                    End If
                Else
                    LastTextBox.Focus()
                End If
            End If
        End If
    End Sub

    Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
        If Not IsNothing(LastTextBox) Then
            Dim i As Integer
            Dim strInt As String = LastTextBox.Name.Remove(0, "TextBox".Length)
            If Integer.TryParse(strInt, i) Then
                If i > 8 Then
                    i = i - 9
                    Dim ctls() As Control = Me.Controls.Find("TextBox" & i, True)
                    If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
                        Dim tb As TextBox = CType(ctls(0), TextBox)
                        tb.Focus()
                    End If
                Else
                    LastTextBox.Focus()
                End If
            End If
        End If
    End Sub

    Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
        If Not IsNothing(LastTextBox) Then
            Dim i As Integer
            Dim strInt As String = LastTextBox.Name.Remove(0, "TextBox".Length)
            If Integer.TryParse(strInt, i) Then
                If i < 63 Then
                    i = i + 9
                    Dim ctls() As Control = Me.Controls.Find("TextBox" & i, True)
                    If ctls.Length > 0 AndAlso TypeOf ctls(0) Is TextBox Then
                        Dim tb As TextBox = CType(ctls(0), TextBox)
                        tb.Focus()
                    End If
                Else
                    LastTextBox.Focus()
                End If
            End If
        End If
    End Sub

End Class
Random Solutions  
 
programming4us programming4us