View Single Post
 
Old 11-21-2014, 11:53 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Where is your attempt?

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Word.Table
Dim oProp As DocumentProperty
Dim lngIndex As Long
  Set oTbl = ActiveDocument.Tables(1)
  For lngIndex = 2 To oTbl.Rows.Count
    On Error GoTo Err_Property
    Set oProp = ActiveDocument.CustomDocumentProperties(fcnCellText(oTbl.Cell(lngIndex, 1)))
    oProp.Value = fcnCellText(oTbl.Cell(lngIndex, 2))
NextEntry:
  Next lngIndex
  ActiveDocument.Fields.Update
lbl_Exit:
  Exit Sub
Err_Property:
  ActiveDocument.CustomDocumentProperties.Add _
    Name:=fcnCellText(oTbl.Cell(lngIndex, 1)), LinkToContent:=False, Value:=fcnCellText(oTbl.Cell(lngIndex, 2)), _
    Type:=msoPropertyTypeString
  Resume NextEntry
End Sub
Function fcnCellText(oCell As Word.Cell) As String
  fcnCellText = Replace(oCell.Range.Text, Chr(13) + Chr(7), "")
  
End Function
I wouldn't use that method. I would create a Product Name and Manufacture content control, map them to a customXMLnode and then copy and paste the controls where I need the same data repeated.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote