vb Excel で実行時エラー 91「オブジェクト変数またはブロック変数が設定されていません」が発生しました (I got an runtime error 91 " Object variable or With block variable not set" in vb excel)


問題の説明

vb Excel で実行時エラー 91「オブジェクト変数またはブロック変数が設定されていません」が発生しました (I got an runtime error 91 " Object variable or With block variable not set" in vb excel)

Sub Extractdatafromwebsite()
Dim ie As InternetExplorer
Dim Eventno As String
Dim doc As HTMLDocument
Eventno = Sheet1.Range("A2").Value


ie.Visible = True
ie.navigate "https://www.bankeauctions.com/#" & Eventno

Do
    DoEvents
    Loop Until ie.readyState = READYSTATE_COMPLETE

Set doc = ie.document
On Error Resume Next
output = doc.getElementById("ContentPlaceHolder1_lblReserverPrice" & Eventno).innerText
Sheet1.Range("B2").Value = output

ie.Quit

ここに画像の説明を入力


リファレンスソリューション

方法 1:

You haven't actually created an instance of IE yet, so there's nothing to make visible

Dim IE As InternetExplorer

Set IE = New InternetExplorer '// <~~ The bit you need

IE.Visible = True

...

When you Dimension a variable, you are simply reserving some memory in order to place something there. Data types (such as Integer or String) do not need to be Set ‑ but Internet Explorer is an Object

An Object needs to be built and in order to do that, the system needs some instructions ‑ a blueprint if you will ‑ of how to build that object. This is called a Class.

You have asked the system to reserve some memory for your IE object, but until you actually create the object and place it in that memory, there is nothing to interact with and so you receive that error.

Hope that makes sense.

方法 2:

You have declared a variable using Dim but you have not initiated an instance. It's like when you're having a baby. You can name it before it's born but you can't really call it (as you call anyone) with its name until it's born (initiated).

Sub Main()

Dim Mike As baby
Set Mike = new baby
Mike.PeekaBoo
'baby laughs
End Sub

Sub Main()
Dim Mike As baby
Mike.PeekaBoo
'Returns an error as an instance of the baby class is not found
End Sub

(by Dita JaiswalSierraOscarAmen Jlili)

リファレンスドキュメント

  1. I got an runtime error 91 " Object variable or With block variable not set" in vb excel (CC BY‑SA 2.5/3.0/4.0)

#vba #excel






関連する質問

2010カスタムリボンにアクセス (access 2010 custom ribbon)

セルに値が保存されているファイルを開く (Open files with values stored in cells)

コンソールはプログラミング言語で制御できますか? (Can consoles be controlled by programming languages?)

このコードを変更して、最後の行の下の行にデータを貼り付けるにはどうすればよいですか? (How do I modify this code to paste in the row under last row with data?)

Selenium-vba クラス名で要素を取得 (Selenium-vba Get element by Class Name)

セルからデータを抽出し、セルをアルファベット順に並べ替えるにはどうすればよいですか? (How do I extract data from a cell and order the cells alphabetically?)

VBAコードがセルをアクティブにしない (VBA code not activating cell)

列をExcel VBAループして、空白以外をコピーして他の3つの列に貼り付けますか? (Excel VBA Loop through Column to Copy and Paste Non Blanks to 3 other Columns?)

コードは 2 つの製品で動作しますが、3 番目の製品コードを追加すると、データが取得されますが、3 番目の製品だけに保存されません。どうしたの? (Code works with two products but when I add a third product code grabs data but doesn't save it only for third product. What's wrong with it?)

シート 2 の範囲内のセル名に基づいてシート (シート 1) を複製して名前を変更するために必要な VBA コード (VBA code needed to duplicate and rename a sheet (Sheet 1) based on cell names in a range on Sheet 2)

signtool.exe エラー: Excel マクロの署名時に SignerSign() が失敗しました (-2147220492/0x800403f4) (signtool.exe Error: SignerSign() failed (-2147220492/0x800403f4) when signing Excel Macro)

Excelで1つの列の「 - 」で区切られたデータを複数に分割する (Divide data separated from ' - ' in one column into more in excel)







コメント