Solved

vb script Microsoft Word tables portion of based on bookmark, count and add rows

Posted on 2016-09-20
1
68 Views
Last Modified: 2016-09-21
Screenshot of table in Word with Bookmark illuminated:  http://www.screencast.com/t/2BExLOfquY

How do I adapt the following so that it counts only the rows in the bookmark and adds a row within the bookmark:
Dim objShell, strPath, wd
Set objShell = CreateObject("Wscript.Shell")
Set wd = CreateObject("Word.Application")
wd.visible = true
strPath = objShell.CurrentDirectory
wd.Documents.Open strPath & "/MakeTableNew.docx"
set tbl  = wd.ActiveDocument.Bookmarks(1).Range.Tables(1)
msgbox tbl.rows.count  'returns 6, should return 3
tbl.rows.add()  'adds row to end of table, should add row to bookmark area
wd.ActiveDocument.SaveAs(strPath & "/MakeTableNewNew.docx")
wd.Quit

The purpose of this is that I plan to do the following steps:
Add bookmarks to a table representing a header, group header, multiple detail and footer regions similar to a report tool
Populate each region with financial data.
0
Comment
Question by:maxdbase
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 50

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 41806838
Hi,

pls try

set tblPart = wd.ActiveDocument.Bookmarks(1).Range
 msgbox tblPart.rows.count  'returns 6, should return 3
 tblPart.rows.add()  'adds row to end of table, should add row to bookmark area

Open in new window

Regards
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question