#1
|
|||
|
|||
Populating a table cell wit document properties
Hello!
I've got a macro that adds rows to a table, but I need it to populate the rows with a document properties and I can't find a syntax that would work. That's what I have so far: Code:
Sub add() Dim oTable As Table Dim oCell As Cell Dim oPrevRow As Row, oNewRow As Row Dim iColumn As Long ' Insert new row Set oTable = ActiveDocument.Tables(1) Set oPrevRow = oTable.Rows(oTable.Rows.Count) oTable.Rows.add Set oNewRow = oTable.Rows(oTable.Rows.Count) oNewRow.Cells(1).Range.Text = "Column 1 Text" oNewRow.Cells(2).Range.Text = "Column 2 Text" oNewRow.Cells(3).Range.Text = "Column 3 Text" oNewRow.Cells(4).Range.Text = "Column 4 Text" oNewRow.Cells(5).Range.Text = "Column 5 Text" End Sub |
#2
|
||||
|
||||
You haven't said what type of property, but the following example uses both built-in and custom properties and should point the way.
Code:
Sub add() Dim oTable As Table Dim oCell As Cell Dim oNewRow As Row Dim oDocProp As DocumentProperty ' Insert new row Set oTable = ActiveDocument.Tables(1) Set oNewRow = oTable.Rows.add For Each oDocProp In ActiveDocument.BuiltInDocumentProperties If oDocProp.name = "Author" Then oNewRow.Cells(1).Range.Text = oDocProp.Value End If If oDocProp.name = "Title" Then oNewRow.Cells(2).Range.Text = oDocProp.Value End If Next oDocProp For Each oDocProp In ActiveDocument.CustomDocumentProperties If oDocProp.name = "MyPropName1" Then oNewRow.Cells(3).Range.Text = oDocProp.Value End If If oDocProp.name = "MyPropName2" Then oNewRow.Cells(4).Range.Text = oDocProp.Value End If If oDocProp.name = "MyPropName3" Then oNewRow.Cells(5).Range.Text = oDocProp.Value End If Next oDocProp End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Thank you so much, exactly what I was looking for!
|
Tags |
document properties, table |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Move table cell contents from one table to another table or cell in same table | donaldadams1951 | Word VBA | 4 | 02-04-2015 03:54 PM |
Cell properties: next cell | htieK | Excel | 5 | 10-28-2014 06:23 PM |
Updating Document Properties without using advanced properties dialogue | thedr9wningman | Word VBA | 3 | 01-20-2014 05:56 PM |
How 2 Save Table Properties & Apply to other table | Popeye.Tom | Word Tables | 1 | 04-24-2013 09:44 PM |
Properties of a Cell | DrDOS | Excel | 1 | 04-06-2012 08:49 PM |