Good Afternoon,
I am trying to build a workbook to process invoices. I've been able to setup the code to go through our payment system login page but when I get to entering the invoice details I get the following error message(s).
"Run-time error '91': Object Variable or With block variable not set"
I believe this has something to do with the following code not being able to find the HTML element, it is there as an "ID" and "Name".
With the above, "BU" gets set to nothing and throws out the runtime 91 error.
If I change the "getElementById" to "getElementsByName" i get a Runtime error 438. with "ElementsByName", If i remove the .Value from BU the code stores the data from excel in vba but does not transfer to the webpage.
FULL CODE :
Any help would be greatly appreciated, I'm at a loss...
Thanks
Tom</vba></runtime></runtime>
I am trying to build a workbook to process invoices. I've been able to setup the code to go through our payment system login page but when I get to entering the invoice details I get the following error message(s).
"Run-time error '91': Object Variable or With block variable not set"
I believe this has something to do with the following code not being able to find the HTML element, it is there as an "ID" and "Name".
Code:
Set BU = .document.getElementById("MI_VCHRQST_ADVW_BUSINESS_UNIT")
BU.Value = ws.Range("A" & ActRow).Value
With the above, "BU" gets set to nothing and throws out the runtime 91 error.
If I change the "getElementById" to "getElementsByName" i get a Runtime error 438. with "ElementsByName", If i remove the .Value from BU the code stores the data from excel in vba but does not transfer to the webpage.
FULL CODE :
Code:
'Option Explicit
Sub INVOICE_PROCESSOR()
'================================================================
'SETTINGS
'Application.ScreenUpdating = False
'Application.Calculation = xlCalculationManual
'Application.DisplayAlerts = False
'================================================================
'VARIABLES
Dim wb As Workbook: Set wb = ThisWorkbook
Dim ws As Worksheet: Set ws = wb.Sheets("INVOICES")
Dim IE As Object: Set IE = New InternetExplorerMedium
Dim ActRow As Integer: ActRow = ws.Range("A:A").Find("Business Unit").Offset(1, 0).Row
Dim EID As HTMLInputElement
Dim PASSWORD As HTMLInputElement
'Dim BU As HTMLInputElement
'Dim VEND_ID As HTMLInputElement
'Dim VEND_LOC As HTMLInputElement
'Dim INV_ID As HTMLInputElement
'Dim INV_DATE As HTMLInputElement
'================================================================
'CODE
'OPEN INTERNET EXPLORER AND NAVIGATE TO AP INPUT PAGE
With IE
.Visible = True
.navigate ws.Range("B1").Value
Do While .Busy
DoEvents
Loop
Do While .readyState <> 4
DoEvents
Loop
'LOGGING IN
On Error GoTo INV_ENTRY
Set EID = .document.getElementById("username")
EID.Value = ws.Range("b2").Value
Set PASSWORD = .document.getElementById("password")
PASSWORD.Value = InputBox("Enter EID Password")
' PASSWORD.Value = ""
.document.forms(0).submit
INV_ENTRY:
Do While .Busy
DoEvents
Loop
Do While .readyState <> 4
DoEvents
Loop
'Application.Wait (Now + TimeValue("00:00:10"))
'BEGIN INVOICE PROCESSING
'!!!!!!!!!!!!! error here
Set BU = .document.getElementById("MI_VCHRQST_ADVW_BUSINESS_UNIT")
BU.Value = ws.Range("A" & ActRow).Value '<<<<<runtime error="" 91
Set BU = .document.getElementsByName("MI_VCHRQST_ADVW_BUSINESS_UNIT")
BU.Value = ws.Range("A" & ActRow).Value '<<<<<runtime error="" 438
Set BU = .document.getElementsByName("MI_VCHRQST_ADVW_BUSINESS_UNIT")
BU = ws.Range("A" & ActRow).Value '<<<<<vba stores="" data="" from="" workbook="" but="" does="" not="" populate="" the="" webpage
'Set VEND_ID = .document.getElementById("MI_VCHRQST_ADVW_VENDOR_ID")
' VEND_ID.Value = ws.Range("B" & ActRow).Value
'
'Set VEND_LOC = .document.getElementById("MI_VCHRQST_ADVW_VNDR_LOC")
' VEND_LOC.Value = ws.Range("C" & ActRow).Value
'
'Set INV_ID = .document.getElementById("MI_VCHRQST_ADVW_INVOICE_ID")
' INV_ID.Value = ws.Range("D" & ActRow).Value
'
'Set INV_DATE = .document.getElementById("MI_VCHRQST_ADVW_INVOICE_DT")
' INV_DATE.Value = ws.Range("E" & ActRow).Value
ws.Range("G" & ActRow).Value = "COMPLETED"
ActRow = ActRow + 1
'================================================================
.Quit
End With
'MsgBox ("COMPLETED")
'================================================================
'RESET SETTINGS
ResetSettings:
'Application.ScreenUpdating = True
'Application.Calculation = xlCalculationAutomatic
'Application.DisplayAlerts = True
End Sub
Any help would be greatly appreciated, I'm at a loss...
Thanks
Tom</vba></runtime></runtime>
Last edited: