Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Dear Support Members,
I have a webpage that contains several hyperlinks. I wish to write some Excel VBA to download/copy the destination of all the hyperlinks. For example, if the webpage contains links to four .jpg images, I would like the Excel VBA to copy those four images to c:\temp Thanks in advance, Christmas May |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Chris
I did try working on this but not yet arrived at a situation where I can store all the targets in a folder. But i have a solution where you can get url of all the hyperlink targets to the destination. I hope this helps and if i do get a solution wehre you can store in a folder, i will let you know... Copy the following code and paste in a new code module. Option Explicit Dim nwSht As Worksheet Sub hyperlinkInformation() Dim IE As Object Dim doc, element Dim shtName As String shtName = InputBox("Give a name to the new sheet") Call Get_New_SHeet(shtName) Set IE = CreateObject("InternetExplorer.Application") IE.Navigate GetUrl IE.Visible = True Do Until IE.busy = False DoEvents Loop Set doc = IE.Document Dim i As Integer i = 2 For Each element In doc.all.tags("A") nwSht.Cells(i, 1) = element.innertext 'prints the text of the hyperlink nwSht.Cells(i, 2) = element 'prints the hyperlink itself 'press ctrl-g to see debug window i = i + 1 Next element MsgBox "Done" End Sub Private Sub Get_New_SHeet(ByVal shtName As String) Set nwSht = ActiveWorkbook.Sheets.Add nwSht.Name = shtName nwSht.Activate With nwSht .Cells(1, 1) = "Link text" .Cells(1, 2) = "Link URL" .Columns(1).ColumnWidth = 35 .Columns(2).ColumnWidth = 50 End With nwSht.Activate End Sub Private Function GetUrl() GetUrl = InputBox("Enter the url for the get the hyperlinks " & _ "on that page/doc", "", _ "http://socko.wordpress.com/site-contents/") If UCase(Left(GetUrl, 7)) < "HTTP://" Then MsgBox "Please enter the url starting with http:// and try again" Exit Function GetUrl = "" End If End Function Go to the following url if to download the example file. http://www.sockofiles.350.com/get=_linktargets=_url.xls I hope this helps. - Selva Fore more info on vba info, visit http://socko.wordpress.com |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Template downloads | New Users to Excel | |||
Schedule downloads | Excel Programming | |||
Schedule Downloads | Excel Programming | |||
File Downloads in VBA | Excel Discussion (Misc queries) |