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.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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?
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,877
Messages
6,175,138
Members
452,614
Latest member
MRSWIN2709

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top