Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating Internet Explorer with VBA

Status
Not open for further replies.

DEtkd

MIS
Oct 1, 2003
4
GB
I am trying to cut down on the time it takes to copy and paste tables from the internet by automating the process. I can get Excel to select and follow an URL in a cell. However I cannot then get VBA to "speak" to Internet Explorer to tell it to selectall and then copy. At the moment I have to do this manually on each webpage then use a seperate sub routine to paste the table in the format I require. Is there anyway I can automate this whole process?? Thank you in advance

Dave
 
I may be able to help if you give a specific example.

I use Excel to open Internet Explorer, submit a request (using the POST method) to the hosts server, then I use either Document.documentElement.innerhtml or Document.documentElement.outerText
to get the whole page, then parse out the info I need. (This also works with static data.)

Depending on what your trying to do, this may work or may not work for you.
 
Cheers sfvb,

will have a look at what you have said. As for the specific example I'll try to explain what I'm trying to do;

I am trying to automate a task that is very time comsuming using VBA. What I would like the code to do is as follows

Open up a webpage (I have managed this part) then select the whole of the webpage (which contains a table of data I need), copy it and then paste it into an excel worksheet. I have tried different methods. One was to use edit, get external data and then use the wizard but that only returned no query data available, and another was to use the QueryTable command.

When using the following code it worked to return the google site eg:

Sub WebAccessTest()
'
' WebAccessTest Macro
'

'
ActiveSheet.Select
With ActiveSheet.QueryTables.Add(Connection:= _
"URL; web address here and file to query" ", Destination:=Range _
("A1")) 'Where you want it placed on ActiveSheet
.Name = "index" 'What you want the Query to be called
.FieldNames = True 'Some of these may need blocking
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlAllTables
.WebFormatting = xlWebFormattingAll
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.Refresh BackgroundQuery:=False
End With
End Sub

However when I put in the site information I required it would not return any information. Would it make a difference if the site was on the intranet rather than the internet?? To access the site you still need to put in the full URL ie www.

I hope this is what you meant.

I will look at using what you have provided already

Thanks Again

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top