Skip to content

Instantly share code, notes, and snippets.

@Tomamais
Created March 24, 2020 23:15
Show Gist options
  • Save Tomamais/9b19f82681b8abe7222a3ab23b18ebd7 to your computer and use it in GitHub Desktop.
Save Tomamais/9b19f82681b8abe7222a3ab23b18ebd7 to your computer and use it in GitHub Desktop.
Live VBA na Veia
Dim driver As WebDriver
Sub ColetaDadosCorreios()
Set driver = New ChromeDriver
With driver
.Get "http://www2.correios.com.br/sistemas/precosPrazos/"
.FindElementById("data").SendKeys Format(DateAdd("d", 1, Now), "dd/MM/yyyy")
.FindElementByName("cepOrigem").SendKeys "01310-200" 'MASP - São Paulo
.FindElementByName("cepDestino").SendKeys "20021-200" 'Museu Nacional do Rio de Janeiro
.FindElementByName("servico").AsSelect().SelectByText ("PAC")
.FindElementByXPath("//*[@id=""spanFormato""]/img[1]").Click
.FindElementByName("embalagem1").AsSelect().SelectByValue ("correiosEmbalagem1")
.FindElementByXPath("//*[@id=""spanTipoEmbalagem""]/div/div[2]/div/div[1]/div/p/button").Click
.FindElementByName("peso").AsSelect().SelectByValue ("1")
.FindElementById("spanCKValDeclarado").Click
.FindElementByName("valorDeclarado").SendKeys "10000"
.FindElementByXPath("//*[@id=""spanBotao""]/input").Click
.SwitchToNextWindow (1000)
Dim novaPlanilha As Worksheet
Set novaPlanilha = ThisWorkbook.Worksheets.Add
.FindElementByXPath("/html/body/div[1]/div[3]/div[2]/div/div/div[2]/div[2]/div[2]/table").AsTable().ToExcel (novaPlanilha.Cells(1, 1))
driver.Quit
End With
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment