1
正如標題所說,我試圖最大化使用以下命令創建一個Internet Explorer窗口:如何使用SHDocVw.InternetExplorer命令最大化由VBA創建的IE窗口?
Set ie = New SHDocVw.InternetExplorer
相反的:
Set ie = CreateObject("InternetExplorer.Application")
下面是完整的代碼:
Sub wpieautologin()
Dim ie As SHDocVw.InternetExplorer
Dim NOME_EMPRESA, CNPJ, CPF, COD_ACESSO As String
Dim Lookup_Range As Range
Set ie = New SHDocVw.InternetExplorer
ie.Visible = False
ie.Navigate "http://www8.receita.fazenda.gov.br/simplesnacional/controleacesso/autentica.aspx?id=6"
NOME_EMPRESA = Range("B8").Value
Set Lookup_Range = Range("B12:E500")
CNPJ = Application.WorksheetFunction.VLookup(NOME_EMPRESA, Lookup_Range, 2, False)
CPF = Application.WorksheetFunction.VLookup(NOME_EMPRESA, Lookup_Range, 3, False)
COD_ACESSO = Application.WorksheetFunction.VLookup(NOME_EMPRESA, Lookup_Range, 4, False)
Do
Loop Until ie.readystate = 4
Call ie.Document.GetElementByID("ctl00_ContentPlaceHolder_txtCNPJ").SetAttribute("value", CNPJ)
Call ie.Document.GetElementByID("ctl00_ContentPlaceHolder_txtCPFResponsavel").SetAttribute("value", CPF)
Call ie.Document.GetElementByID("ctl00_ContentPlaceHolder_txtCodigoAcesso").SetAttribute("value", COD_ACESSO)
ie.Visible = True
>'What should I write here to maximize my IE Window?
>'Already tried a few solutions, but they works only when the IE is created by the command
>'Set ie = CreateObject("InternetExplorer.Application")
#INSERT COMMAND TO MAXIMIZE WINDOW HERE
End Sub
那麼,我該如何做到這一點?
感謝您的答覆!當我使用你的代碼時,首先它說這個代碼必須更新到一個64位版本...所以,而不是'Private Declare Function ShowWindow Lib「user32」_'我必須使用'Private Declare PtrSafe Function ShowWindow Lib「user32」 _' ...好的,第一個錯誤已修復! 因此,修復上述錯誤後,我得到以下錯誤:'不兼容的類型',然後調試器標記以下語句:'ShowWindow ie.hwnd'你知道爲什麼嗎? –
在我的結尾沒有64位excel,但試試這個鏈接:http://www.jkp-ads.com/articles/apideclarations.asp。 – cyboashu
@rfw - 將'ByVal hwnd as Long'更改爲'ByVal hwnd as LongPtr'。 – Comintern