Run time error '91' (Object variable or with block variable not set) for IE

Akiabhi

New Member
Joined
Mar 9, 2017
Messages
3
Hi,
I am new to VBA coding to access IE and fill the web form over Intranet.

I am trying to click a button HTML code below:

HTML-
<INPUT onclick='return btnAddNewLine_OnClick();WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl00$contentPH$btnAddLine", "", true, "", "", false, false))' id=ctl00_contentPH_btnAddLine title="Add a new line to this timesheet" class=button style="WIDTH: 135px" type=submit value="Add New Line" name=ctl00$contentPH$btnAddLine>

The below code gives me an error Run time error '91' (Object variable or with block variable not set).

VBA Code:
[/B]

Sub Test ()
Dim appIE As Object
Dim sURL As String, infoStr As String

  Set appIE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
  sURL = "https://Timesheets/TimesheetHome.aspx"
With appIE
    .Navigate sURL
    .Visible = True
End With

Do While appIE.Busy Or appIE.ReadyState <> 4
    DoEvents
Loop
appIE.document.all.Item("ctl00$contentPH$btnAddLine").Click
End Sub

[B]


Kindly help.
 

Some videos you may like

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,466
Try replacing the Click line with:
VBA Code:
Dim inputElement As Object
Do
    Set inputElement = appIE.document.all.Item("ctl00$contentPH$btnAddLine") 'either
    'Set inputElement = appIE.document.getElementById("ctl00_contentPH_btnAddLine") 'or
    DoEvents
Loop While inputElement Is Nothing
inputElement.Click
I've given 2 alternatives for the Set inputElement line.
 

Akiabhi

New Member
Joined
Mar 9, 2017
Messages
3
Hi, Thanks for the solution but it does not come out from loop mode as the input element does not have any value. Please suggest as the website is over an intranet.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,466
Is the element in a frame? If so you need to access the document of the frame.

Why are you using GetObject and what is that id? Try using the conventional CreateObject for IE.

As it's an intranet I can't really help further.
 

Akiabhi

New Member
Joined
Mar 9, 2017
Messages
3
I tried using Create object then I got an error

"Run- time error ' 2147417848 (80010108)'
Automation error
The object invoked has disconnected from its client.

Any suggestions?
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,466
Post your code. Kill all the iexplore.exe processes.

With your intranet you might need to use InternetExplorerMedium, which requires a reference to MS Internet Controls.
 

Watch MrExcel Video

Forum statistics

Threads
1,114,337
Messages
5,547,349
Members
410,785
Latest member
phillippaige
Top