?
Solved

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

Posted on 2016-09-20
1
Medium Priority
?
89 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 52

Accepted Solution

by:
Rgonzo1971 earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This video shows and describes the main difference between both orientations in Microsoft Word. Viewers will understand when to use each orientation and how to get the most out of them.
Suggested Courses

765 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