Ola. Estou extraindo alguns dados de uma tabela html de um ERP que devido a limitações me levam a isso. Enfim, o problema consiste de, ao copiar a tabela e tentar cola-lo com range.paste ou pastespecial da erro.
O código completo:
Sub Coletar_Web()
Dim ie As New SHDocVw.InternetExplorer
Dim clip As DataObject
With ie
.Visible = False
.navigate "URL"
While .Busy Or .readyState <> 4: DoEvents: Wend
On Error GoTo Copy
With .document
.getElementById("nome_u").Value = "usuario"
.getElementById("senha").Value = "senha"
.getElementById("submit").Click
End With
While .Busy Or .readyState <> 4: DoEvents: Wend
Debug.Print .LocationURL
Copy:
With ie
.Visible = True
.navigate "URL"
Do While .Busy: DoEvents: Loop
Do While .readyState <> 4: DoEvents: Loop
End With
Set ieTable = ie.document.getElementById("itens")
If Not ieTable Is Nothing Then
Set clip = New DataObject
clip.SetText "<html>" & ieTable.outerHTML & "</html>"
clip.PutInClipboard
Sheet1.Range("A10").Paste
End If
End With
End Sub
O erro ocorre nesse bloco:
Set ieTable = ie.document.getElementById("itens")
If Not ieTable Is Nothing Then
Set clip = New DataObject
clip.SetText "<html>" & ieTable.outerHTML & "</html>"
clip.PutInClipboard
Sheet1.Range("A1").Paste
End If
Mais especificamente no Sheet1.Range("A1").Paste, lembrando que já usei diversas variações de Paste e PasteSpecial para tentar executar essa tarefa.
Tentando simular essa tarefa manualmente para então reproduzi-lo em vba, o ideal seria usando a opção Matching Destination formating ao colar por VBA, mas também não consegui reproduzir isso de forma eficiente. Copiando e colando dados simples para chegar a essa opção, o ideal foi PasteSpecial xlValues, mas também retorna erro.
EDIT:
Continuando com essa saga, tentei gravar um macro colando os dados e obtive o seguinte resultado:
.PasteSpecial Format:="HTML", link:=False, DisplayAsIcon:=False, NoHTMLFormatting:=True
Porém o erro persiste, provavelmente não esta relacionado ao .PasteSpecial
, mas sim como estou armazenando o dados.