+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 24

Thread: hyperlinks

  1. #1
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    hyperlinks

    Hi,

    I have a worksheet with hundrets of hyperlinks in column A. these hyperlinks are leading to web pages that have the same structure, but different details.
    what I need to make is a macro that enter the link, copies particular details to separate workshhet, then copies 2 particuar cells (which are always in the same place) and paste it to column B and C, in the same row as the hyperlink.
    then goes to next link...., and till the end of my list.

    sorry for my english. if something is not clear, pls ask
    Last edited by afgi; 10-05-2010 at 07:49 AM.

  2. #2
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: hyperlinks

    What have you got so far ?
    Please post a sample workbook to clarify your question.



  3. #3
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,151

    Re: hyperlinks

    hi afgi

    does this help ..
    Option Explicit
    Sub test()
    Dim hLink As Object
    For Each hLink In Worksheets(1).Hyperlinks
        Debug.Print hLink.Name
    Next
    End Sub
    Last edited by pike; 09-27-2010 at 05:24 AM. Reason: forgot code tags
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  4. #4
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: hyperlinks

    hi,

    pls find the excel table attached.
    1. column A contains a link to the auction
    2. column B contains URL

    3. column C - I want it to contain name of the auction
    4. column D - I want this to have price of the auction

    so, as I presume, it has to go to specific web page, copy it to separate worksheet, and then copy particular cells to columns C and D in particular rows.

    I have this VBA code, but this is far from what I want and this is not a loop one. I need modification to make it a loop makro and that will extract requred data to all of rows with hyperlinks
    Sub test()
    '
    ' test Makro
    '
    
    '
        Range("B2").Select
        ActiveCell.FormulaR1C1 = "http://moda.allegro.pl/1219836365-i1219836365.html"
        With ActiveCell.Characters(Start:=1, Length:=50).Font
            .Name = "Arial Unicode MS"
            .FontStyle = "Normalny"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleSingle
            .ThemeColor = xlThemeColorLight1
            .TintAndShade = 0
            .ThemeFont = xlThemeFontNone
        End With
        Sheets("aaaaaa").Select
        With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;http://moda.allegro.pl/1219836365-i1219836365.html", Destination:=Range( _
            "$A$1"))
            .Name = "1219836365-i1219836365"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .WebSelectionType = xlSpecifiedTables
            .WebFormatting = xlWebFormattingNone
            .WebTables = "1,3"
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
            .Refresh BackgroundQuery:=False
        End With
        Range("C1").Select
        Selection.Copy
        Sheets("links").Select
        Range("C2").Select
        ActiveSheet.Paste
        Sheets("aaaaaa").Select
        Range("B7").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("links").Select
        Range("D2").Select
        ActiveSheet.Paste
    End Sub
    Attached Files Attached Files
    Last edited by afgi; 09-27-2010 at 10:11 AM.

  5. #5
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,151

    Re: hyperlinks

    hi afgi

    try this ... problem is I cant read what is meant to be the price or name but you will get the idea
    Sub Port()
       Dim sht1 As Worksheet
       Dim qryTbl As QueryTable
       Dim XRow As Variant
    
       Set sht1 = ThisWorkbook.Worksheets("Here")
    
       For Each XRow In Range("B2:B6")
        Nrow = XRow.Address
       Set qryTbl = sht1.QueryTables.Add(Connection:="URL;" & XRow, _
       Destination:=sht1.Range("A1"))
    
       With qryTbl
           .BackgroundQuery = True
           .WebSelectionType = xlSpecifiedTables
           .WebTables = "2"
           .WebFormatting = xlWebFormattingAll
           .Refresh BackgroundQuery:=False
           .SaveData = True
       End With
      
       With sht1
          .Range("B2").Copy Destination:=Sheets("links").Range(Nrow).Offset(0, 1)
       .Range("B3").Copy Destination:=Sheets("links").Range(Nrow).Offset(0, 2)
       End With
    Next XRow
    End Sub
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  6. #6
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: hyperlinks

    hi Pike,

    it does not work well

    I am getting "Run-time error '9'" Subscript out of range message.

    and regarding Name and Price: it is just at top of page.

    so first link name is "OD ZARA-STYLE BIKER 9001 CZARNY KURTKA SKÓRA__XXL" (on the right hend side of the small picture

    and price is "109,99 zł za sztukę" (this is what you will get in one cell in excel)

    many thanks

  7. #7
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,151

    Re: hyperlinks

    Hi afgi,
    try this workbook.. I may have changed something to your original
    Attached Files Attached Files
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  8. #8
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: hyperlinks

    Dear Pike,

    almost perfect)) but I have few problems.

    1. it works only till row 6. even when I change <For Each XRow In Range("B2:B6") > to for example <For Each XRow In Range("B4:B9")>
    2. it would be good idea to cancel the data in worksheet "Here" every time it download new one. because when I have 200 link, this would make worksheet that takes a lot of memory
    Many thanks

  9. #9
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: hyperlinks

    hi,

    one more. can we not use that Click button. I am not sure how to upload it to other worksheets. thanks

  10. #10
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: hyperlinks

    Dear Pike,

    moreover, it sometimes work on your file, but I get an error on this line ".Refresh BackgroundQuery:=False", when I put more rows to work on. sometimes it collapse on 10th sometimes on 26th row. I need it to be more stable and to work on many different workbooks, if possible. many thanks for what you did till now

  11. #11
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: hyperlinks

    Hi,

    and of course I still do not get why it works onl on your worksheet...
    Last edited by afgi; 09-28-2010 at 10:00 AM.

  12. #12
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,151

    Re: hyperlinks

    hi afgi
    You will always have problems when importing from the web as Table values depending on the address/layer cange and sites also change. I think the problem was I changed the sheet name from "aaaaaa" to "Here"
    to find the correct table you have to read the source code
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  13. #13
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: hyperlinks

    Hi,

    I do understand that. but it was not that, because I change the name in source code. I am real beginer in VBA, so I think I made some mistakes during transporting to other excel sheets. anyway, I have updated code. it delates content of worksheet Here after each loop, so it wont colapse when working on many links. pls see it attached below and case is solved. thanks Pike
    Option Explicit
    Sub Port()
       Dim sht1 As Worksheet
       Dim qryTbl As QueryTable
       Dim XRow As Variant
       Dim Nrow As String
       Set sht1 = ThisWorkbook.Worksheets("Here")
    
       For Each XRow In Range("B2:B52")
        Nrow = XRow.Address
       Set qryTbl = sht1.QueryTables.Add(Connection:="URL;" & XRow, _
       Destination:=sht1.Range("A1"))
    
       With qryTbl
           .BackgroundQuery = True
           .WebSelectionType = xlSpecifiedTables
           .WebTables = "1,3"
           .WebFormatting = xlWebFormattingAll
           .Refresh BackgroundQuery:=False
           .SaveData = True
       End With
      
       With sht1
          .Range("C1").Copy Destination:=Sheets("links").Range(Nrow).Offset(0, 1)
       .Range("B7").Copy Destination:=Sheets("links").Range(Nrow).Offset(0, 2)
       End With
        Sheets("Here").Select
        Cells.Select
        Selection.Delete Shift:=xlUp
        Sheets("links").Select
    Next XRow
    End Sub

  14. #14
    Forum Guru pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2010
    Posts
    5,151

    Re: hyperlinks

    Thats good I forgot to add that you nedd this bit
      For Each XRow In Range("B2", Cells(Rows.Count, 2).End(xlUp))
    so it works for the dynamic range
    regards pike

    If the solution helped please donate
    here to the RSPCA

    Sites worth visiting;

    J&R Solutions - royUK

    AJP Excel Information - Andy Pope

    Spreadsheet Toolbox

    VBA for smarties - snb

  15. #15
    Registered User
    Join Date
    09-13-2010
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    57

    Re: hyperlinks

    hi,

    where shuold I put that and what it does? what is dynamic range?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0