Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I maximize an IE window created by VBA with SHDocVw.InternetExplorer command?

Tags:

excel

vba

shdocvw

As the title says, I'm trying to maximize an internet explorer window that was created using the following command:

Set ie = New SHDocVw.InternetExplorer

Instead of:

Set ie = CreateObject("InternetExplorer.Application")

Here's the full code:

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

So, how can I achieve this?

like image 632
dot.Py Avatar asked Dec 28 '16 17:12

dot.Py


People also ask

Can VBA control Microsoft edge?

As of 25th April 2022, you can now directly automate Edge IE Mode with VBA without any additional third party-software.


1 Answers

This could be done like this as well.

ie.FullScreen = True

or

ie.TheaterMode = True

Then you don't to declare a function.

like image 98
UnknownQ Avatar answered Oct 31 '22 16:10

UnknownQ