Solved

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

Posted on 2016-09-20
1
39 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
1 Comment
 
LVL 48

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

A Knowledge Base That Stays Up-to-Date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now