Thread: [Solved] Working with word tables.
View Single Post
 
Old 12-01-2015, 03:21 AM
PRA007's Avatar
PRA007 PRA007 is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Lightbulb Working with word tables.

I have in word table hyperlinked numbers.

I want to populate table wit winhttp Request.

I tried picking code from here and there to explain what I want.

Code:
Sub USPTOAbstHTML1()
Application.ScreenUpdating = False
Dim Rng As Range, Tbl As table, StrTxt As String, HttpReq As Object, i As Long, doc As MSHTML.HTMLDocument
Set HttpReq = CreateObject("Microsoft.XMLHTTP")
Set oHtml = New HTMLDocument
With ActiveDocument.Range
    For Each Tbl In .Tables
        With Tbl
            For i = 1 To .Rows.Count
                With .Cell(i, 2).Range
                    With .Find
                        .ClearFormatting
                        .Replacement.ClearFormatting
                        .Text = "US [0-9],[0-9]{3},[0-9]{3}"
                        .Replacement.Text = ""
                        .Forward = True
                        .Wrap = wdFindStop
                        .Format = False
                        .MatchWildcards = True
                        .Execute
                    End With
                        If .Find.Found Then
                            If .Hyperlinks.Count > 0 Then
                                HttpReq.Open "GET", .Hyperlinks(1).Name, False
                                HttpReq.send
                                oHtml.body.innerHTML = HttpReq.responseText
                                StrTxt = oHtml.getElementsByTagName("p")(0).innerText
                            End If
                        End If
                            .Collapse wdCollapseEnd
                            .Find.Execute
                End With
                With .Cell(i, 3).Range
                .InsertAfter vbCr & "Abstract:" & StrTxt
                End With
            Next
        End With
    Next
End With
Set HttpReq = Nothing
Application.ScreenUpdating = True
End Sub
I could not figure out how to make With .Cell(i, 3).Range runs with With .Cell(i, 2).Range find.found.

This code inputs data everywhere in .Cell(i, 3).Range irrespective of .find.found. in Cell(i, 2).Range

How to make them sync.

file at:
https://sites.google.com/site/rtsk2015/fo
HTTP.docx
In file I have in column 4 also put data what I want in column 3 for explanation.

Last edited by PRA007; 12-01-2015 at 08:43 PM.
Reply With Quote