|
-
Jan 17th, 2012, 12:30 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Getting Web Page data into Excel
I'm using the code below to go to a web page, copy all of the data and paste to clipboard. The web page, when first opened, has its focus set on a field that is expecting user input. So, when I paste what's in the clipboard into Excel, I get "Enter a name or symbol", which is the field's solicitation. How can I skip, unfocus, or otherwise get around this solicitation, so that when I 'copy all' I in fact get the entire web page and not the field solicitation? Thanks.
HTML Code:
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate (url)
Do Until .ReadyState = 4: DoEvents: Loop
.ExecWB 17, 0 '// SelectAll
.ExecWB 12, 2 '// Copy selection
.Quit
End With
ActiveSheet.Paste
-
Jan 17th, 2012, 12:33 PM
#2
Re: Getting Web Page data into Excel
I think you would rather use a more solid technique.
Check out Get External Data > From Web
What version of Excel are you using?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 17th, 2012, 12:40 PM
#3
Thread Starter
Hyperactive Member
Re: Getting Web Page data into Excel
-
Jan 17th, 2012, 12:55 PM
#4
Re: Getting Web Page data into Excel
Did you check out the get external data? Its in the Data tab
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jan 17th, 2012, 12:56 PM
#5
Thread Starter
Hyperactive Member
Re: Getting Web Page data into Excel
When I use the 'Get External Data from Web' method (which I would then record as a macro because I'll be looping throough several web retrievals), I get only text data. I need to gain access to the hyperlinks that are on the web page. Thanks.
-
Jan 17th, 2012, 01:18 PM
#6
-
Jan 17th, 2012, 01:24 PM
#7
Re: Getting Web Page data into Excel
Here is an example
Code:
Option Explicit
Sub Sample()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "Google.Com"
Do Until .ReadyState = 4: DoEvents: Loop
Range("A1").Value = IE.Document.documentElement.innerhtml
.Quit
End With
End Sub
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jan 17th, 2012, 01:43 PM
#8
Thread Starter
Hyperactive Member
Re: Getting Web Page data into Excel
Thanks, but that does not seem to be working. All I get is a lot of text data in "A1", but no hyperlinks that are down further on the web page.
-
Jan 17th, 2012, 01:46 PM
#9
Re: Getting Web Page data into Excel
Can you share the URL with us?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jan 17th, 2012, 01:51 PM
#10
Thread Starter
Hyperactive Member
Re: Getting Web Page data into Excel
This is my starting url: http://www.nasd100.com/2012/01/stron...an-9-2012.html
On the web page that's retrieved, I'm trying to capture the urls that go with 'Balance Sheet' and 'Income Statement'. I'll use these urls to load up Excel with the repective data. Balance Sheet url is: http://moneycentral.msn.com/investor...tr&symbol=ANAC
-
Jan 17th, 2012, 01:54 PM
#11
Thread Starter
Hyperactive Member
Re: Getting Web Page data into Excel
-
Jan 17th, 2012, 01:57 PM
#12
Re: Getting Web Page data into Excel
>>>On the web page that's retrieved, I'm trying to capture the urls that go with 'Balance Sheet' and 'Income Statement'.
I have opened that page but I am unable to locate that link. Where exactly is that link?
Edit: Ok. Looking at the new URL now.
Last edited by Siddharth Rout; Jan 17th, 2012 at 02:14 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jan 17th, 2012, 02:08 PM
#13
Frenzied Member
Re: Getting Web Page data into Excel
within body line 341+ after <spn>finacials</span>
nothing particularly unique about this part of page
her to help if help is needed
-
Jan 17th, 2012, 02:41 PM
#14
Re: Getting Web Page data into Excel
Ok the code is ready. Do you specifically want the URL OF 'Balance Sheet' and 'Income Statement' or just the innerHTML?
EDIT
Here is the code to get just the URL's
Code:
Option Explicit
Sub Sample()
Dim MyArray1() As String, MyArray2() As String, TempARR() As String
Dim InComeURL As String, BalanceURL As String
Dim IE As Object
Dim i As Long
Dim tbl
Set IE = CreateObject("InternetExplorer.Application")
With IE
.Visible = True
.Navigate "http://investing.money.msn.com/investments/stock-price?symbol=ANAC&"
Do Until .ReadyState = 4: DoEvents: Loop
Set tbl = .Document.getElementById("LeftNav")
MyArray1 = Split(tbl.innerHTML, vbCrLf)
For i = 0 To UBound(MyArray1)
If InStr(1, MyArray1(i), "Income Statement") Then
TempARR = Split(MyArray1(i), "><A href=""")
MyArray2 = Split(TempARR(1), """>")
InComeURL = MyArray2(0)
End If
If InStr(1, MyArray1(i), "Balance Sheet") Then
TempARR = Split(MyArray1(i), "><A href=""")
MyArray2 = Split(TempARR(1), """>")
BalanceURL = MyArray2(0)
End If
Next i
End With
MsgBox "Income Statement URL is : " & vbCrLf & InComeURL _
& vbCrLf & vbCrLf & _
"Balance Sheet URL is : " & vbCrLf & BalanceURL
IE.Quit
Set IE = Nothing
End Sub
Last edited by Siddharth Rout; Jan 17th, 2012 at 02:56 PM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Jan 18th, 2012, 10:55 AM
#15
Thread Starter
Hyperactive Member
Re: Getting Web Page data into Excel
Very nice. Thanks to all of you.
-
Jan 18th, 2012, 01:34 PM
#16
Thread Starter
Hyperactive Member
Re: [RESOLVED] Getting Web Page data into Excel
The code you gave works and I'm really appreciative of it, but there seems to be a little glitch in the Balance Sheet url that causes it not to work. "AMP;" occurs twice and it is not in the Properties url of the Balance Sheet hyperlink. No big deal as I can remove these characters with code, but if there's a simple change to your code that would fix it, that would be great. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|