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". - Public Sub csi()
-
Dim appIE As InternetExplorer
-
Dim xlApp As Excel.Application
-
Dim wsData As Worksheet
-
Set xlApp = Application
-
Set wsData = xlApp.Worksheets("CSIInq")
-
Set appIE = New InternetExplorer
-
AppActivate ("Exact Website Title Name Here")
-
appIE.ExecWB 17, 2 <<--- This line is where the error comes up
-
appIE.ExecWB 12, 0
-
AppActivate ("CSI")
-
Workbooks("CSI.XLS").Activate
-
Range("A1").Select
-
ActiveSheet.Paste
-
Set appIE = Nothing
-
-
End Sub
17 19774
Have you set a reference to the library "Microsoft Internet Controls"?
Yes, that reference has been set
OK change this line - AppActivate ("Exact Website Title Name Here")
to -
objIE.Navigate "Exact Website Title Name Here"
Does that help?
No, I get the same error as above on the same line (#9).
Yes, the error is on #9. I just went searching and saw the same thing, but I was having trouble changing the registry
I'm going to see if I can get someone with more experience using this library to check this out.
Mary
Try the below as a Template: - 'First, you must set a Reference to the Microsoft Internet Controls
-
Dim appIE As InternetExplorer
-
Const conURL As String = "http://www.msn.com"
-
-
DoCmd.Hourglass True
-
-
Set appIE = New InternetExplorer
-
-
appIE.Navigate conURL
-
-
'You must wait until the Page is fully loaded
-
Do
-
Loop Until appIE.ReadyState = READYSTATE_COMPLETE
-
-
'Copy and Paste the Web Page
-
appIE.ExecWB 17, 2
-
appIE.ExecWB 12, 0
-
-
'Web Page should now be in the Clipboard
-
-
DoCmd.Hourglass False
-
-
'Clean Up, being careful of Scope
-
'appIE.Quit
-
'Set appIE = Nothing
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.
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.
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?
Is it an absolute requirement that the Window already be Open?
Yes because it's a secure website so I wouldn't be able to access it from just entering the URL
Back to the Drawing Board, you may have a problem...
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
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
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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.
|
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
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |