+ Reply to Thread
Results 1 to 3 of 3

Need help Importing Data using web query to specific Columns

Hybrid View

raghav007 Need help Importing Data... 06-19-2011, 02:20 AM
venkat1926 Re: Need help Importing Data... 06-19-2011, 05:28 AM
raghav007 Re: Need help Importing Data... 06-19-2011, 06:56 AM
  1. #1
    Registered User
    Join Date
    06-19-2011
    Location
    Pune,India
    MS-Off Ver
    Excel 2007
    Posts
    2

    Need help Importing Data using web query to specific Columns

    Hello Friends ,

    I need your help with two issues that am facing.
    Am trying to copy information from a webpage http://tinyurl.com/linktopage2

    It is a directory.Containing links to every member it has. The info on each page is divided in 3 parts. Name , Business Type , Contact Information.

    http://i54.tinypic.com/2j9tm8.jpg
    You can see the image on above link to understand what am trying to do.

    Now my question is , is it possible to have info collected in specified cells the way I am wanting to do.

    And my second question is the macro that am using to fetch information is putting information horizontally in excel.

    Here is the macro.
     
    Sub LoopThrough()
    Dim WSO As Worksheet
    Set WSO = ActiveSheet
    For Each Cell In WSO.Range("A1:A5")
    ThisURL = "URL;" & Cell.Value
    
    With ActiveSheet.QueryTables.Add(Connection:= _
    ThisURL, Destination:= _
    Range("$A$23"))
    .Name = "ListingDetails.asp?MemID=2302"
    .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 = "19,""FormPaddingL"",""FormPaddingL"""
    .WebPreFormattedTextToColumns = True
    .WebConsecutiveDelimitersAsOne = True
    .WebSingleBlockTextImport = False
    .WebDisableDateRecognition = False
    .WebDisableRedirections = False
    .Refresh BackgroundQuery:=False
    End With
    ActiveWindow.SmallScroll Down:=-2
    
    Next Cell
    End Sub
    
    Sub Getlinks()
    For Each h1 In ActiveSheet.Hyperlinks
    Cells(hl.Parent.Row, 2).Value = hl.Address
    Next hl
    End Sub
    I am only two days old at programming. So would highly appreciate if anyone here could help me with this.Thanks to all in advance.
    Last edited by raghav007; 06-19-2011 at 06:55 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Need help Importing Data using web query to specific Columns

    I am sending you a file raghava main.xls.
    see sheet1. it has the member ship numbers form A2 to A6
    After running the macro "test" you get the sheets whose names are the remember ships numbers (same as A2 to A6 in sheet1). see those new member sheets.; I agree some cosmetic changes have to ;be done. let us think about it later. but do you not want some thing like this.


    suppose you are generally satisfied with the sheet 1170 to 1175 then for RETESTING
    you run the second macro "undo" first and then run the first macro "test" and see whether you get the same result

    Note: as you are downloading data and rearranging it it may take some time. for these six members it takes about 20 seconds. that is about 3.5 second for each member). if you have 30 members it will take little less than 2 minutes. keep this in mind.At end of the running the macro "test" you get confirmation message "macro over"

    the macros are in vb editor of the file. still I am giving the macro here also

    Sub test()
    Dim url As String, memurl As String, r As Range, c As Range, dest As Range
    Application.ScreenUpdating = False
    Worksheets("sheet1").Activate
    Set r = Range(Range("a2"), Range("A2").End(xlDown))
    url = "http://delhichamber.co.in/ListingDetails.asp?MemID="
    For Each c In r
    memurl = url & c.Value
    'MsgBox memurl
    Worksheets.Add
    ActiveSheet.Name = c.Value
     With ActiveSheet.QueryTables.Add(Connection:="URL;" & memurl, Destination:=Range("A1"))
            .Name = "ListingDetails.asp?MemID=1770"
            .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 = """FormPaddingL"""
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
            .Refresh BackgroundQuery:=False
            End With
            '---------------
            With ActiveSheet
           Set dest = .Cells(Rows.Count, "A").End(xlUp).Offset(5, 0)
           .UsedRange.Copy
           dest.PasteSpecial , Transpose:=True
           Range(.Range("A1"), dest.Offset(-1, 0)).EntireRow.Delete
            
        End With
        
    Worksheets("sheet1").Activate
        
    Next c
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "macro over"
    End Sub
    
    
    Sub undo()
    Dim j As Integer, k As Integer
    Application.DisplayAlerts = False
    j = Worksheets.Count
    For k = j To 1 Step -1
    If Left(Worksheets(k).Name, 5) = "Sheet" Then GoTo nextk
    Worksheets(k).Delete
    nextk:
    Next k
    Application.DisplayAlerts = True
    End Sub
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    06-19-2011
    Location
    Pune,India
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Need help Importing Data using web query to specific Columns

    Thanks Venkat. I appreciate your reply. I`ll go through the file once I am on my desk and if I still get a problem i`ll get back to u.
    Thanks again.

+ 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.6.0 RC 1