Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-25-2015, 12:46 AM
PRA007's Avatar
PRA007 PRA007 is offline Merging data from Two word documents based on number search Windows 7 32bit Merging data from Two word documents based on number search Office 2010 32bit
Competent Performer
Merging data from Two word documents based on number search
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default Merging data from Two word documents based on number search

I Have two separate word documents
One having patent numbers in table like this.


I want to takepatent number from the table of one document and search it in the second document and want to add text associated with that number back to the original table like this.





Is it possible to do this using any word macro function?
Reply With Quote
  #2  
Old 04-03-2015, 12:01 AM
PRA007's Avatar
PRA007 PRA007 is offline Merging data from Two word documents based on number search Windows 7 32bit Merging data from Two word documents based on number search Office 2010 32bit
Competent Performer
Merging data from Two word documents based on number search
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default I Think this is in-appropriate Question.

I think this is matter for database management thing.
Reply With Quote
  #3  
Old 04-04-2015, 12:27 AM
gmayor's Avatar
gmayor gmayor is offline Merging data from Two word documents based on number search Windows 7 64bit Merging data from Two word documents based on number search Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Not inappropriate, just no-one got around to it

Based on your illustration, and assuming the list document is consistent in its formatting and all the numbers are prefixed 'US', the following macro should work for you.

Change the names and paths of the two documents to reflect what you have. If you don't want the formatting in the table to match the formatting in the list, then replace the two instances of 'formattedtext' with 'text'
http://www.gmayor.com/installing_macro.htm
Code:
Option Explicit

Sub UpdateTable()
Dim oSource As Document
Dim oTarget As Document
Dim oRng As Range
Dim strFind As String
    'Open the document with the table
    Set oTarget = Documents.Open("C:\Path\EN\Target.docx")
    'Open the document with the list
    Set oSource = Documents.Open("C:\Path\EN\Source.docx")
    Set oRng = oSource.Range
    With oRng.Find
        With oRng.Find
            Do While .Execute(FindText:="US[0-9]{5,}", _
                              MatchWildcards:=True)        'The number as shown in the list document
                strFind = Trim(Replace(oRng.Text, "US", ""))        'Remove the 'US' Prefix from the found number
                oRng.MoveEnd wdParagraph, 5        'Move the end of the range that encompasses the found text the end of the required text
                oRng.MoveStart wdParagraph, 1        'Move the start of the range to start of the paragraph after the paragraph with the found text
                FillTable oTarget, oRng, strFind        'Call the sub to fill the table with the text from the range
                oRng.Collapse 0
            Loop
        End With
    End With
lbl_Exit:
    Set oSource = Nothing
    Set oTarget = Nothing
    Set oRng = Nothing
    Exit Sub
End Sub

Private Sub FillTable(oDoc As Document, _
                      oRng As Range, _
                      strFind As String)
Dim oCell As Range
Dim oFind As Range
Dim iRow As Long
    Set oFind = oDoc.Range
    With oFind.Find
        Do While .Execute(FindText:=strFind)
            iRow = oFind.Information(wdEndOfRangeRowNumber)
            Set oCell = oDoc.Tables(1).Rows(iRow).Cells(5).Range
            oCell.End = oCell.End - 1
            oCell.FormattedText = oRng.FormattedText        'use this line to keep the formatting
            'oCell.Text = oRng.Text 'use this line if the formatting is not required
            Exit Do
        Loop
    End With
lbl_Exit:
    Set oCell = Nothing
    Set oFind = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #4  
Old 05-25-2015, 03:06 AM
PRA007's Avatar
PRA007 PRA007 is offline Merging data from Two word documents based on number search Windows 7 32bit Merging data from Two word documents based on number search Office 2010 32bit
Competent Performer
Merging data from Two word documents based on number search
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default Everything fine. Just wanted to add exception.

While adding the text only one problem is there are some pr-efilled cells which I don't want to disturb. I want to add exception that only empty target cells must occupy with text. Moreover it is only adding text having numbering in first column. I want to add text irrespective of text in first column. I Just want to add text to cell totally empty.
Reply With Quote
  #5  
Old 11-21-2015, 04:35 AM
PRA007's Avatar
PRA007 PRA007 is offline Merging data from Two word documents based on number search Windows 7 32bit Merging data from Two word documents based on number search Office 2010 32bit
Competent Performer
Merging data from Two word documents based on number search
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

I tried but did not get answer to this question. Can I ask again with proper instruction and files?
Reply With Quote
  #6  
Old 11-21-2015, 06:57 AM
gmayor's Avatar
gmayor gmayor is offline Merging data from Two word documents based on number search Windows 7 64bit Merging data from Two word documents based on number search Office 2010 32bit
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

If I understand your request correctly, you need to add a condition to modify only unfilled cells e.g.

Code:
Set oCell = oDoc.Tables(1).Rows(iRow).Cells(5).Range
    oCell.End = oCell.End - 1
    If Len(oCell) = 0 Then 'Add This line
        oCell.FormattedText = oRng.FormattedText        'use this line to keep the formatting
        'oCell.Text = oRng.Text 'use this line if the formatting is not required
        Exit Do
    End If 'And this one
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #7  
Old 11-23-2015, 05:30 AM
PRA007's Avatar
PRA007 PRA007 is offline Merging data from Two word documents based on number search Windows 7 32bit Merging data from Two word documents based on number search Office 2010 32bit
Competent Performer
Merging data from Two word documents based on number search
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

welcome back sir.
Code just worked fine[for my old files].
Unfortunately my database provider have changed entire file system so I will ask accordingly in new thread.
can be marked as solved.
Reply With Quote
Reply

Tags
data merge, ms word 2010, vba code

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
search on multiple word documents Guy Roth Word 7 03-06-2017 01:31 PM
Merging data from Two word documents based on number search Merging Word documents and keeping the formatting exactly as it appears in the original document NovaScotia Word 4 01-21-2015 11:44 PM
Merging data from Two word documents based on number search Advanced search in Word documents beirput Word 3 11-10-2014 02:53 AM
Merging data from Two word documents based on number search Merging bibliographies with word documents using separate master lists Cimballi Word 3 07-01-2014 03:45 AM
How to preserve or Retain bookmarks during Merging of word documents ramsgarla Word 2 09-18-2012 08:59 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:08 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft