Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-15-2015, 03:50 AM
milena milena is offline Populating a table cell wit document properties Windows 7 64bit Populating a table cell wit document properties Office 2013
Novice
Populating a table cell wit document properties
 
Join Date: Apr 2015
Posts: 4
milena is on a distinguished road
Default 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
So is there a way to replace "Column Text" string with a document property?
Reply With Quote
  #2  
Old 04-15-2015, 05:56 AM
gmayor's Avatar
gmayor gmayor is offline Populating a table cell wit document properties Windows 7 64bit Populating a table cell wit document properties 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

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
Reply With Quote
  #3  
Old 04-15-2015, 07:28 AM
milena milena is offline Populating a table cell wit document properties Windows 7 64bit Populating a table cell wit document properties Office 2013
Novice
Populating a table cell wit document properties
 
Join Date: Apr 2015
Posts: 4
milena is on a distinguished road
Default

Thank you so much, exactly what I was looking for!
Reply With Quote
Reply

Tags
document properties, table

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populating a table cell wit document properties 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
Populating a table cell wit document properties Cell properties: next cell htieK Excel 5 10-28-2014 06:23 PM
Populating a table cell wit document properties Updating Document Properties without using advanced properties dialogue thedr9wningman Word VBA 3 01-20-2014 05:56 PM
Populating a table cell wit document properties 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

Other Forums: Access Forums

All times are GMT -7. The time now is 12:51 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