Página 1 de 1

Preciso acessar um botão em um site via VBA Excel

Enviado: Sáb Jun 27, 2020 11:36 am
por momagalhaes97
Bom dia, estou com um problema para clicar um botão que não tem ID nem nome, somente com href e class.
Segue o código:

Código: Selecionar todos

Sub teste2()

    Dim ht As HTMLDocument
    Dim IE As Object
    Dim btn As HTMLButtonElement
    Dim objLink As Object
    Dim objLink1 As Object
    Dim ele As Object
    
    Set IE = CreateObject("InternetExplorer.application")
    
    With IE
        .Visible = True
        .navigate ("http://estatisticas.cetip.com.br/astec/series_v05/paginas/web_v04_10_01_estoque.asp?str_Ativo=CFF&str_TipoInformacao=Negociações Definitivas&str_TipoInformacaoModelo=0&int_Idioma=1")
While .Busy Or .readyState <> 4:
            DoEvents:
        Wend


For Each objLink In IE.document.getElementsByTagName("a")


    If objLink.href = ("javascript:void(0);") Then

          objLink.Click

          Exit For

        End If

    Next objLink


With IE
While .Busy Or .readyState <> 4: DoEvents: Wend





For i = 1 To 2
SendKeys "DEB"

'While .Busy Or .readyState <> 4: DoEvents: Wend
Application.Wait (Now + TimeValue("0:00:02"))

Next i

SendKeys "Negociações D"


While .Busy Or .readyState <> 4: DoEvents: Wend


''''' A partir daqui a macro não executa o código que faz rigorosamente a mesma coisa que o getElements antes do SendKeys.

With IE

For Each objLink1 In IE.document.getElementsByClassName("bt-padrao mt-35")


        If objLink1.href = ("javascript:Fun_EnvioChecaDados(1,'F1')") > 0 Then
              objLink1.Click

              Exit For

            End If
Next objLink1

End With

End With

End With

End Sub

fica no site: http://estatisticas.cetip.com.br/astec/ ... _NivelBD=2

Séries Históricas -> Dados por ativo -> Escolhe o Ativo -> Informações -> E então quer pesquisar, que abre uma nova aba com os dados

Re: Preciso acessar um botão em um site via VBA Excel

Enviado: Sáb Jun 27, 2020 8:55 pm
por Raygsson
Também gostaria de saber, nessa página tem 03 Frames, o seu elemento esta no Frame name="ativo". Quando a pagina tem apenas 01 Frame geralmente consigo manipular tipo IE.Document.Frames(0).Document.All("xxxx").

<frameset rows="50px, 50px, *" border="no" frameborder="0" framespacing="0">
<frame name="ativo" id="ativo" src="web_v04_05_ativo.asp?str_Modulo=Ativo&amp;int_Idioma=1&amp;int_Origem=2" border="no" frameborder="0" framespacing="0" marginwidth="0" marginheight="0" noresize="" scrolling="no" style="width: 100%; height: 100px;">
<frame name="info" id="info" src="web_v04_90_01_vazio.asp" border="no" frameborder="0" framespacing="0" marginwidth="0" marginheight="0" noresize="" scrolling="no" style="width: 100%; height: 30px;">
<frame name="detalhe" id="detalhe" src="web_v04_90_01_vazio.asp" border="no" frameborder="0" framespacing="0" marginwidth="0" marginheight="0" noresize="" scrolling="no" style="width: 100%;">
</frameset>

Re: Preciso acessar um botão em um site via VBA Excel

Enviado: Dom Jun 28, 2020 1:35 pm
por Raygsson
Deu um bom trabalho achar a solução pra isso, porém aprendi muita coisa no processo. Segue o código:

Sub CETIP()
Dim IE As InternetExplorer
Set IE = New InternetExplorer

IE.Visible = True
IE.Navigate ("http://estatisticas.cetip.com.br/astec/ ... _NivelBD=2")
While IE.Busy Or IE.ReadyState <> 4: DoEvents: Wend

IE.Document.getElementsByClassName("lk-dados-ativo")(0).Click
While IE.Busy Or IE.ReadyState <> 4: DoEvents: Wend

Dim MeuFrame As Object 'O FRAME PRECISA SER DECLARADO COMO OBJETO
Set MeuFrame = IE.Document.Frames.Item(0).Document 'ACESSA O FRAMESET/CONJUNTO DE FRAMES
Set MeuFrame = MeuFrame.Frames.Item(0).Document 'ACESSA O 1ª FRAME DO FRAMESET, CONJUNTO INICIA EM "0"

For Each Elemento In MeuFrame.getElementsByTagName("select") 'AGORA QUE ACHEI MEU FRAME VOU PERCORRER TODOS OS SEUS ELEMENTOS NA TAG QUE ESTOU PROCURANDO "SELECT"
If (LCase(Elemento.Name) = LCase("ativo")) Then 'VOU COMPARAR O NOME DOS ELEMENTOS, ESTOU ATRAS DO ELEMENTO COM NOME "ATIVO" QUE ESTA NA TAG "SELECT"
Set MeuElemento = Elemento 'QUANDO ACHAR O ELEMENTO VOU SETAR/VINCULAR A UMA VARIAVEL
Exit For
End If
Next Elemento

MeuElemento.Value = "Debentures" 'DEPOIS CONSIGO MANIPULAR ESSA VARIAVEL QUE REPRESENTA O ELEMENTO NA PÁGINA
MeuElemento.onchange 'ATUALIZA A PÁGINA DEPOIS QUE SELECIONAR A OPÇÃO

Stop
IE.Quit

End Sub

Re: Preciso acessar um botão em um site via VBA Excel

Enviado: Dom Jun 28, 2020 1:47 pm
por Raygsson
Não cheguei até a parte do botão pois o desafio estava em achar os elementos no Frame.
Vi que voce deu um jeitinho de manipular a página com SendKeys, porém agora pode usar a forma correta.
basta analisar o codigo e seguir o mesmo padrão pras demais ações.

Preencher google forms com vba

Enviado: Ter Jun 30, 2020 6:08 am
por Lutgens10
Olá alguem sabe como preencher um google forms com vba , eu consegui algumas linhas mas ele não preenche tudo ,se alguem puder me ajudar como preencher tudo agradeceria e muito

Código: Selecionar todos


Public Sub ConectaWeb()
On Error Resume Next
Dim endereço As String
Dim mostra As Boolean

Dim i, n, x As Integer
endereço = "https://docs.google.com/forms/d/e/1FAIpQLSc-d6XfqSS_-P2SCRiIJMKU477NPlzFnkjVHe0RqO2DMSc4xA/viewform"
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate (endereço)
While IE.ReadyState <> 4
Wend
IE.Visible = True
IE.document.forms.Item(0).Item(2).Value = "Comentários / Sugestões"
IE.document.forms.Item(0).Item(3).Value = Sheets(1).Range("A1")
IE.document.forms.Item(0).Item(4).Value = Sheets(1).Range("A2")
IE.document.forms.Item(0).Item(5).Value = Sheets(1).Range("A3")
IE.document.forms.Item(0).submit
   
While IE.ReadyState <> 4
Wend
End Sub


Re: Preciso acessar um botão em um site via VBA Excel

Enviado: Qua Jul 01, 2020 12:43 am
por Raygsson
Testei preenchendo 02 campos pegando pela classe :

IE.Document.GetElementsByClassName("quantumWizTextinputPaperinputPlaceholder exportLabel")(0).innerhtml = ""
IE.Document.GetElementsByClassName("quantumWizTextinputPaperinputInput exportInput")(0).Value = "teste1"

IE.Document.GetElementsByClassName("quantumWizTextinputPapertextareaPlaceholder exportLabel")(0).innerhtml = ""
IE.Document.GetElementsByClassName("quantumWizTextinputPapertextareaInput exportTextarea")(0).Value = "teste2"

Re: Preciso acessar um botão em um site via VBA Excel

Enviado: Qua Jul 01, 2020 7:09 pm
por Lutgens10
Raygsson escreveu: Qua Jul 01, 2020 12:43 am Testei preenchendo 02 campos pegando pela classe :

IE.Document.GetElementsByClassName("quantumWizTextinputPaperinputPlaceholder exportLabel")(0).innerhtml = ""
IE.Document.GetElementsByClassName("quantumWizTextinputPaperinputInput exportInput")(0).Value = "teste1"

IE.Document.GetElementsByClassName("quantumWizTextinputPapertextareaPlaceholder exportLabel")(0).innerhtml = ""
IE.Document.GetElementsByClassName("quantumWizTextinputPapertextareaInput exportTextarea")(0).Value = "teste2"





VALEU CARA MUITO OBRIGADO ABRIU MINHA CABEÇA ISSO VALEU MESMO , [RESOLVIDO],SE VOCE CONSEGUISSE PREENCHER OS RADIOS TBM SIM E NAO SERIA TOP HAHAHAHAHA MAS VALEU PELA FORÇA SE UDESSE DAR UM MILHAO DE LIKES , DEPOIS EU FUI MUDANDO O NUMERO 0 POR 2 , 3 ATE PREENCHER TUDO,QUE PRA AJUDAR O GOOGLE FORMS NAO CRIA TUDO BONITINHO PR ID OU POR NAME TIPO input tal id="email" ou name="email"

Código: Selecionar todos

 
'Quantidade Evento tipo1
IE.Document.GetElementsByClassName("quantumWizTextinputPaperinputPlaceholder exportLabel")(20).innerhtml = ""
IE.Document.GetElementsByClassName("quantumWizTextinputPaperinputInput exportInput")(20).Value = "34"