• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 45
  • Last Modified:

Microsoft Word Automation

Using:
Microsoft Word
Word Tables
VBA

I need a way to populate and hide a unique key value in each row.
Having a hidden column would be ideal.

How can I do that?
0
maxdbase
Asked:
maxdbase
  • 6
  • 5
1 Solution
 
Neil FlemingIndependent consultantCommented:
You cannot really "hide" a column in a Word table. However, each cell in the table has an unused "ID" property.

You can set this property to achieve what you want.

The following routine, for instance, assigns an ID based on the table row to the first cell in each row. The ID is invisible to the user, and you don't need a column to keep it in.
Sub NumberRows()
Dim tt As Table, rr As Row, aCell As Cell

Set tt = ActiveDocument.Tables(1)
For Each rr In tt.Rows
Set aCell = rr.Cells(1)
aCell.ID = rr.Index
Next

End Sub

Open in new window


Note that the ID property is a string, so if you want to re-extract a row number you need to convert back to a number. But you may want to use some entirely different key, I guess.
0
 
maxdbaseAuthor Commented:
This is amazing,  I hope I can make it work.
I'll test and post results back here.
0
 
maxdbaseAuthor Commented:
Works like a charm.  I plan to use this to store a hidden unique key and then I can add an update to the server from within the Word document that passes the unique Key and the new value.
thanks, this is a big help!
1
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
Neil FlemingIndependent consultantCommented:
glad to be of help
0
 
maxdbaseAuthor Commented:
I can make this a follow up question if you prefer, but I feel like I want to ask if there are any resources out there
that focus on extending the value of Microsoft Word Tables in terms of making them like data sets.
I have a finance application that by using Word instead of report tools, I can reduce a lot of manual\
data handling in the midst of preparing budget and finance statements.

Thanks for all!

Keith
0
 
maxdbaseAuthor Commented:
specifically, I am using http to retrieve complex datasets from an api
0
 
Neil FlemingIndependent consultantCommented:
A Word Table is quite a basic thing. It really only stores text in its cells, and you can't do even a 10th of what you can do in Excel with a Word table.

Would it be an option to manipulate your datasets in Excel and then copy the results to Word as tables?
0
 
maxdbaseAuthor Commented:
Hmm, that is an interesting idea.  Never thought about it and that is why asked originally.
So, would the following be a realistic direction for me to move towards:

Use VB Script, C#,  Powershell or other scripting approach

Loop through my config.xml file (contains attributes that drive content, behavior, data, etc  

navigate to the subject table
Open Excel
copy contents of table into excel
do some stuff
copy excel stuff back to word table
go to next loop item
0
 
Neil FlemingIndependent consultantCommented:
Yes.

In theory, you could probably drive the whole exercise from VBA code in Excel. That is, use Excel VBA to download data from your API (is it XML data?), drop into Excel, manipulate it, and paste the results as Word tables.

As you'll see, even if you manually copy a cell range in Excel and hit "paste" in Word, the result is a table.
0
 
maxdbaseAuthor Commented:
OK, Neil, I see that, yes, drive it from Excel.  Although, I will try it from Word as well so I have more options that are
execute-ready.   The Excel approach you brought up fits in really well with one of the use cases which is to have
a console (in Excel) that provides master control over a collection of similar Word documents.  The Excel manages
the file folder with all the documents and I run the macro from that.

Big break through you aimed me toward, using Excel to extend the power of tables in Word.  Maybe even use accdb or some form of
in memory database to do the same.  

Thanks for expanding my thinking, I really need it :-)

HNY
K
0
 
Neil FlemingIndependent consultantCommented:
Happy New Year to you. Let me know if you need further help.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now