473,394 Members | 1,778 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to Copy Data From Website to Excel

Hi,

I'm relatively new to VBA but I am trying to copy data from a website (this website is currently running and will be the same) and paste to defined sheet in Excel. Below is the code that I have thus far, however, I am receiving an error "Method 'ExecWB' of object 'IWebBrowser2' failed".

Expand|Select|Wrap|Line Numbers
  1. Public Sub csi()
  2. Dim appIE As InternetExplorer
  3. Dim xlApp As Excel.Application
  4. Dim wsData As Worksheet
  5. Set xlApp = Application
  6. Set wsData = xlApp.Worksheets("CSIInq")
  7. Set appIE = New InternetExplorer
  8. AppActivate ("Exact Website Title Name Here")
  9. appIE.ExecWB 17, 2  <<--- This line is where the error comes up
  10. appIE.ExecWB 12, 0
  11. AppActivate ("CSI")
  12. Workbooks("CSI.XLS").Activate
  13. Range("A1").Select
  14. ActiveSheet.Paste
  15. Set appIE = Nothing
  16.  
  17. End Sub
Sep 30 '10 #1
17 19774
MMcCarthy
14,534 Expert Mod 8TB
Have you set a reference to the library "Microsoft Internet Controls"?
Sep 30 '10 #2
Yes, that reference has been set
Sep 30 '10 #3
MMcCarthy
14,534 Expert Mod 8TB
OK change this line
Expand|Select|Wrap|Line Numbers
  1. AppActivate ("Exact Website Title Name Here")
to
Expand|Select|Wrap|Line Numbers
  1. objIE.Navigate "Exact Website Title Name Here"
Does that help?
Sep 30 '10 #4
No, I get the same error as above on the same line (#9).
Sep 30 '10 #5
MMcCarthy
14,534 Expert Mod 8TB
Are you sure the error is happening at line #9 and not line #10. Check out the remarks section on this method on the msdn website.

http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx
Sep 30 '10 #6
Yes, the error is on #9. I just went searching and saw the same thing, but I was having trouble changing the registry
Sep 30 '10 #7
MMcCarthy
14,534 Expert Mod 8TB
I'm going to see if I can get someone with more experience using this library to check this out.

Mary
Sep 30 '10 #8
ADezii
8,834 Expert 8TB
Try the below as a Template:
Expand|Select|Wrap|Line Numbers
  1. 'First, you must set a Reference to the Microsoft Internet Controls
  2. Dim appIE As InternetExplorer
  3. Const conURL As String = "http://www.msn.com"
  4.  
  5. DoCmd.Hourglass True
  6.  
  7. Set appIE = New InternetExplorer
  8.  
  9. appIE.Navigate conURL
  10.  
  11. 'You must wait until the Page is fully loaded
  12. Do
  13. Loop Until appIE.ReadyState = READYSTATE_COMPLETE
  14.  
  15. 'Copy and Paste the Web Page
  16. appIE.ExecWB 17, 2
  17. appIE.ExecWB 12, 0
  18.  
  19. 'Web Page should now be in the Clipboard
  20.  
  21. DoCmd.Hourglass False
  22.  
  23. 'Clean Up, being careful of Scope
  24. 'appIE.Quit
  25. 'Set appIE = Nothing
Sep 30 '10 #9
Great!! Is it possible to change the constant URL to activating the open window with a specific title? I ask because the website is based off of several logins and if I try to retrieve it another way, the session will time out.
Oct 1 '10 #10
ADezii
8,834 Expert 8TB
You can change the URL to anything you like, but to the best of my knowledge, a New Instance of IE will be opened when Navigating to this URL.
Oct 1 '10 #11
Well, the website will already be open since I'll be logged in and if I put the URL in the code then it will give me a "session expired" message. There is no way to switch windows to copy the data and then come back to paste it?
Oct 1 '10 #12
ADezii
8,834 Expert 8TB
Is it an absolute requirement that the Window already be Open?
Oct 1 '10 #13
Yes because it's a secure website so I wouldn't be able to access it from just entering the URL
Oct 1 '10 #14
ADezii
8,834 Expert 8TB
Back to the Drawing Board, you may have a problem...
Oct 1 '10 #15
Denburt
1,356 Expert 1GB
After rereading this thread several times I thought I might throw my two cents in...

There are a number of routines that have been written that can grab the handle of the the internet explorer window and return the information you are requesting yet your understanding of VBA may make this difficult to accomplish.

Have you considered using a Web query? You can use the import window to view the page then log in once you log in select the info you want and go from there. I know this method has some security issues so you may want to consider that when using it with passwords and other sensitive information. I have used this method for log in pages in the past and had decent results the pitfall of this is when you need to log in you will need to edit the Web query and use the wizards window to log in. I hope this helps, let us know.

Here is some more info on the Web query:Web queries
Oct 7 '10 #16
I have used Web queries in the past and I tried with this but it tells me that the "session expired". I haven't tried logging in through the Web Query window because there are different pop-ups that you will need to get open when logging in so I figured that because of that issue, web queries wouldn't work
Oct 8 '10 #17
Try flipping from this:
appIE.ExecWB 17, 2
appIE.ExecWB 12, 0

to this:
IE.ExecWB 17, 0 '// SelectAll
IE.ExecWB 12, 2 '// Copy selection
Nov 22 '10 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Faith | last post by:
Hello. I need to take a column from Excel(unknown amount of rows) that will be selected by the user and copy those cells. Then I will need to paste those cells into the first column in a Data...
1
by: Steven Stewart | last post by:
I have a user who has been using Excel for a while to keep statistics and print reports. She finds using it cumbersome because of long formulas and a lot of copying and pasting. I have designed...
5
by: Jonny | last post by:
Hello, I have created a button on my form which when pressed does the following : 1) Run a pre-defined Macro, which is picking up a query and running my data to excel. However, I need the...
4
by: phong.lee | last post by:
Here is an issue i've been trying to figure out which i do not have an answer to. Basically i have an excel spreadsheet which has data that i copy and paste from another resource. I also created...
0
by: eyal | last post by:
Hello, I want to open 2 workbook, , lets say workbook1 and workbook2 now I want to copy data from a sheet name "TEST" in workbook2 and paste the data to a sheet named "TEST" in workbook. now...
0
by: BStrick | last post by:
I've searched the net to no avail. I'm looking for a way to copy data from MS Excel into the clipboard, parse it out and paste that data into a vb.net 2003 data grid to be munipulated further.
0
by: Sonnich | last post by:
Hi all! I have 2 problems with opening data in Excel. I have one file creating an array, or actually a number of dim arExport_pdf() dim arExport_pdf2() dim arExport_pdf3() k=0 k2=0
10
by: sanou | last post by:
Hi does anyone know if the following is possible? I have an excel spreadsheet with values that i need transferred to a certain website's form. for instance, i have a value in excel spreadsheet...
4
by: Elavarasi | last post by:
hi I want to import data from excel sheet to ms access database in asp. sample code if possible regards ela...
1
by: reshma khan f | last post by:
Hi All, I m using Escel in VB6 .In that i want to copy datas from excel to datagrid.Not all datas but the selected one so that other can easily follow up. Note that m using ADODB connection in my...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.