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?
maxdbaseAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Neil FlemingConsultant and developerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Neil FlemingConsultant and developerCommented:
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 FlemingConsultant and developerCommented:
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 FlemingConsultant and developerCommented:
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 FlemingConsultant and developerCommented:
Happy New Year to you. Let me know if you need further help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.