![]() |
|
|
|
#1
|
||||
|
||||
|
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
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. |
|
#2
|
||||
|
||||
|
Apology for asking silly questions as inexperienced in VBA.
After reviewing the code I figure out the mistake. Putting the .cell 3 within if find.found works ok. |
|
| Tags |
| word vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Word tables: prevent word from highlighting whole cell when I highlight text | skylark53 | Word | 2 | 08-04-2015 08:12 AM |
Header Rows in Tables Not Working
|
Andy Pilkington | Word | 2 | 10-10-2014 12:36 AM |
Tables in Word
|
angalis428 | Word | 1 | 01-06-2012 01:12 PM |
working with excel tables in MS word
|
radman154 | Word Tables | 1 | 03-25-2011 12:04 AM |
| Word tables | nbudd | Word Tables | 1 | 05-09-2010 06:31 AM |