I'm trying to write a VBA code which allows me to copy data from an existing open IE tab maybe by sending a CTRL+A & CTRL+C with SendKey
method and then pasting it to a sheet on Excel.
I have tried "Get Data from Web" but that doesn't work since I need to enter username/password and can't setup a getElementbyId
lines.
So I found some code, that scans the open tabs of an already active Internet explorer session, but I want to make VBA Switch to the tab that matched and Copy the text from this website.
Sub AAA()
marker = 0
Set objShell = CreateObject("Shell.Application")
IE_count = objShell.Windows.Count
For x = 0 To (IE_count - 1)
On Error Resume Next ' sometimes more web pages are counted than are open
my_url = objShell.Windows(x).Document.Location
my_title = objShell.Windows(x).Document.Title
If my_url Like "http://www.cnn.com" & "*" Then 'compare to find if the desired web page is already open
Set ie = objShell.Windows(x)
marker = 1
Exit For
Else
End If
Next
If marker = 0 Then
MsgBox ("A matching webpage was NOT found")
Else
'Switch to the tab that matched and Copy the text from this website..
End If
End Sub