#1
|
|||
|
|||
Help Writing VBA Code using the HideMark property
Hello,
I am running office 2013. In word, I have a table with rows. These rows are filled by a mail merge. Sometimes, the rows are completely empty. When this occurs, I would like the rows to automatically shrink to size 0. Currently they cannot do so because of the hidden next cell glyph in each cell. I know there is a way to use VBA and the HideMark property to tell word to ignore those glyphs when defining the cell height however, I'm not sure how to go about writing the code for it. Please Help. Thank you. Here is a link to what I need to do. http://officeopenxml.com/WPhideMark.php |
#2
|
||||
|
||||
The preferred way of handling this would be to not create the unwanted rows in the first place. How you go about doing that depends on whether you need a variable number of rows or whether some required rows simply have no data (e.g. a row for a cell phone but the record doesn't have one).
The alternative would be to use a macro to delete, not just hide, the rows post-merge.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
The problem is that whether the row is filled or not depends on a number of variables in the records I am sinking. And at over 300 records, manual deletion would be a pain. Does anyone know how to write the VBA code for the Hidemark property?
|
#4
|
||||
|
||||
What do you mean by manual deletion? You could just write a macro to delete every row with no data, it shouldn't take that long to process. I personally haven't heard of the Hidemark property until seeing this post.
|
#5
|
|||
|
|||
I'm not sure that a macro that runs post merge will work for our application but can you link me to the code for one and I will work on implementing it and making it work. Thanks.
|
#6
|
||||
|
||||
Just pop a command button on your document and give this code a try:
Code:
'/////////////////////////////////////////////////////////// '//////////////////CommandButton1_Click///////////////////// '/////This function deletes all empty rows from a table///// '/////////////////////////////////////////////////////////// Private Sub CommandButton1_Click() For Each Row In ActiveDocument.Tables(1).Rows 'MsgBox Row.Cells(1).Range.Text If (Row.Cells(1).Range.Text = Chr(13) & Chr(7)) Then Row.Delete Next Row '/////////////////////////END/////////////////////////////// End Sub *EDIT* Woops, you can remove the MsgBox line (it's commented out anyways). I was using it for testing. |
#7
|
|||
|
|||
Great thanks! I'll give this a try and see what I can do to make it work for us.
|
#8
|
||||
|
||||
Quote:
The code provided by jpb103 will delete (not just hide) the entire row if even just the first cell on the row is empty. It's not clear whether that's what you want, or whether the entire row must be empty. At this stage, you haven't provided enough information for anyone to know what kind of table your mailmerge generates. For example, do the number of records for each table vary, or is it that some records have empty fields. If it's the former, a Directory merge may be the way to go, instead of the Letter merge you're now using.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Tags |
hidemark, vba |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Link Watermark to custom property | kerend | Word | 0 | 04-08-2012 05:03 AM |
QuickParts - custom document property | untttt | Word | 2 | 06-09-2011 05:24 PM |
Access to the property of the current table | b0x4it | Word VBA | 2 | 05-26-2011 06:25 AM |
Writing code with C# and VB.NET to create Outlook add-ins and other projects | kistou | Outlook | 0 | 01-13-2010 04:23 AM |
set icon for user property | nav1982 | Outlook | 0 | 11-11-2009 05:40 AM |