Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Spankit115 Spankit115 is offline
external usenet poster
 
Posts: 2
Default Automatic Hiding of Tables based upon value in first cell

I am creating a Word 2002 document from mail merge that may have hundreds of
records (and so hundreds of pages), usually generating 2 or 3 pages per
record. The data (from my family history hobby) is being merged onto the
document into separate tables. For example the first table would be the
persons name and address, then the second table could be names of parents,
the third table names of grandparents, the fourth great-grandparents, etc.

The problem is that in many cases there is no actual data in every table and
so this is resulting in empty tables and wasted paper as there is no need to
print the empty tables.

I can produce the data so that I can put a flag as the first cell for each
table to indicate if it should be hidden or not.

I am therefore looking to run a macro after the mail-merge to go through the
document and see if there is any value in the first cell of the table, if so,
no problem, if no value then I want to hide the whole table so that nothing
is shown and the rest of the data moves up. Then carry on down through the
document repeating the process. I should then have a document that contains
some pages with a record that has only one table, other records with maybe 3
tables, etc.

I have never done a Word macro before so some simple tips and steps would be
appreciated. Many thanks in advance.
  #2   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Automatic Hiding of Tables based upon value in first cell

The following macro will delete any tables in the document in which the
first cell in the first row is empty:

Dim i As Long
Dim cell1 As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set cell1 = .Tables(i).Cell(1, 1).Range
cell1.End = cell1.End - 1
If cell1 = "" Then
cell1.Tables(1).Delete
End If
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Spankit115" wrote in message
...
I am creating a Word 2002 document from mail merge that may have hundreds
of
records (and so hundreds of pages), usually generating 2 or 3 pages per
record. The data (from my family history hobby) is being merged onto the
document into separate tables. For example the first table would be the
persons name and address, then the second table could be names of parents,
the third table names of grandparents, the fourth great-grandparents, etc.

The problem is that in many cases there is no actual data in every table
and
so this is resulting in empty tables and wasted paper as there is no need
to
print the empty tables.

I can produce the data so that I can put a flag as the first cell for each
table to indicate if it should be hidden or not.

I am therefore looking to run a macro after the mail-merge to go through
the
document and see if there is any value in the first cell of the table, if
so,
no problem, if no value then I want to hide the whole table so that
nothing
is shown and the rest of the data moves up. Then carry on down through the
document repeating the process. I should then have a document that
contains
some pages with a record that has only one table, other records with maybe
3
tables, etc.

I have never done a Word macro before so some simple tips and steps would
be
appreciated. Many thanks in advance.



  #3   Report Post  
Posted to microsoft.public.word.tables
Spankit115 Spankit115 is offline
external usenet poster
 
Posts: 2
Default Automatic Hiding of Tables based upon value in first cell

Hi Doug,

Wow! That is just about perfect. Many thanks for your help with this.

I have tested this out and it works beautifully except one last bit that
would finish it off.

I have a couple of records where table 1 has nothing, table 2 has data,
table 3 has nothing and table 4 has data. There is a 1 line gap between each
table but when I run the macro to delete the tables, it leaves 2 lines gap in
between the remaining tables. Is there any way to clear this up? Maybe
something along the lines that when you delete a table, also delete the next
line after the table? Is that possible.

This whole area of macros is opening up so many new ways of using Word that
I will go out buy some books on this!

Thanks again!

"Doug Robbins - Word MVP" wrote:

The following macro will delete any tables in the document in which the
first cell in the first row is empty:

Dim i As Long
Dim cell1 As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set cell1 = .Tables(i).Cell(1, 1).Range
cell1.End = cell1.End - 1
If cell1 = "" Then
cell1.Tables(1).Delete
End If
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Spankit115" wrote in message
...
I am creating a Word 2002 document from mail merge that may have hundreds
of
records (and so hundreds of pages), usually generating 2 or 3 pages per
record. The data (from my family history hobby) is being merged onto the
document into separate tables. For example the first table would be the
persons name and address, then the second table could be names of parents,
the third table names of grandparents, the fourth great-grandparents, etc.

The problem is that in many cases there is no actual data in every table
and
so this is resulting in empty tables and wasted paper as there is no need
to
print the empty tables.

I can produce the data so that I can put a flag as the first cell for each
table to indicate if it should be hidden or not.

I am therefore looking to run a macro after the mail-merge to go through
the
document and see if there is any value in the first cell of the table, if
so,
no problem, if no value then I want to hide the whole table so that
nothing
is shown and the rest of the data moves up. Then carry on down through the
document repeating the process. I should then have a document that
contains
some pages with a record that has only one table, other records with maybe
3
tables, etc.

I have never done a Word macro before so some simple tips and steps would
be
appreciated. Many thanks in advance.




  #4   Report Post  
Posted to microsoft.public.word.tables
Greg Maxey Greg Maxey is offline
external usenet poster
 
Posts: 285
Default Automatic Hiding of Tables based upon value in first cell

I'm not Doug, but perhaps this will work for you:

Sub Test()
Dim i As Long
Dim cell1 As Range
Dim oRng As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set cell1 = .Tables(i).Cell(1, 1).Range
cell1.End = cell1.End - 1
If cell1 = "" Then
Set oRng = cell1
cell1.Tables(1).Delete
oRng.Delete
End If
Next i
End With
End Sub

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

"Spankit115" wrote in message
...
Hi Doug,

Wow! That is just about perfect. Many thanks for your help with this.

I have tested this out and it works beautifully except one last bit that
would finish it off.

I have a couple of records where table 1 has nothing, table 2 has data,
table 3 has nothing and table 4 has data. There is a 1 line gap between
each
table but when I run the macro to delete the tables, it leaves 2 lines gap
in
between the remaining tables. Is there any way to clear this up? Maybe
something along the lines that when you delete a table, also delete the
next
line after the table? Is that possible.

This whole area of macros is opening up so many new ways of using Word
that
I will go out buy some books on this!

Thanks again!

"Doug Robbins - Word MVP" wrote:

The following macro will delete any tables in the document in which the
first cell in the first row is empty:

Dim i As Long
Dim cell1 As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set cell1 = .Tables(i).Cell(1, 1).Range
cell1.End = cell1.End - 1
If cell1 = "" Then
cell1.Tables(1).Delete
End If
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Spankit115" wrote in message
...
I am creating a Word 2002 document from mail merge that may have
hundreds
of
records (and so hundreds of pages), usually generating 2 or 3 pages per
record. The data (from my family history hobby) is being merged onto
the
document into separate tables. For example the first table would be the
persons name and address, then the second table could be names of
parents,
the third table names of grandparents, the fourth great-grandparents,
etc.

The problem is that in many cases there is no actual data in every
table
and
so this is resulting in empty tables and wasted paper as there is no
need
to
print the empty tables.

I can produce the data so that I can put a flag as the first cell for
each
table to indicate if it should be hidden or not.

I am therefore looking to run a macro after the mail-merge to go
through
the
document and see if there is any value in the first cell of the table,
if
so,
no problem, if no value then I want to hide the whole table so that
nothing
is shown and the rest of the data moves up. Then carry on down through
the
document repeating the process. I should then have a document that
contains
some pages with a record that has only one table, other records with
maybe
3
tables, etc.

I have never done a Word macro before so some simple tips and steps
would
be
appreciated. Many thanks in advance.






  #5   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default Automatic Hiding of Tables based upon value in first cell

Use

Dim i As Long
Dim cell1 As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set cell1 = .Tables(i).Cell(1, 1).Range
cell1.End = cell1.End - 1
If cell1 = "" Then
Set cell1 = cell1.Tables(1).Range
cell1.End = cell1.End + 1
cell1.Delete
End If
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Spankit115" wrote in message
...
Hi Doug,

Wow! That is just about perfect. Many thanks for your help with this.

I have tested this out and it works beautifully except one last bit that
would finish it off.

I have a couple of records where table 1 has nothing, table 2 has data,
table 3 has nothing and table 4 has data. There is a 1 line gap between
each
table but when I run the macro to delete the tables, it leaves 2 lines gap
in
between the remaining tables. Is there any way to clear this up? Maybe
something along the lines that when you delete a table, also delete the
next
line after the table? Is that possible.

This whole area of macros is opening up so many new ways of using Word
that
I will go out buy some books on this!

Thanks again!

"Doug Robbins - Word MVP" wrote:

The following macro will delete any tables in the document in which the
first cell in the first row is empty:

Dim i As Long
Dim cell1 As Range
With ActiveDocument
For i = .Tables.Count To 1 Step -1
Set cell1 = .Tables(i).Cell(1, 1).Range
cell1.End = cell1.End - 1
If cell1 = "" Then
cell1.Tables(1).Delete
End If
Next i
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Spankit115" wrote in message
...
I am creating a Word 2002 document from mail merge that may have
hundreds
of
records (and so hundreds of pages), usually generating 2 or 3 pages per
record. The data (from my family history hobby) is being merged onto
the
document into separate tables. For example the first table would be the
persons name and address, then the second table could be names of
parents,
the third table names of grandparents, the fourth great-grandparents,
etc.

The problem is that in many cases there is no actual data in every
table
and
so this is resulting in empty tables and wasted paper as there is no
need
to
print the empty tables.

I can produce the data so that I can put a flag as the first cell for
each
table to indicate if it should be hidden or not.

I am therefore looking to run a macro after the mail-merge to go
through
the
document and see if there is any value in the first cell of the table,
if
so,
no problem, if no value then I want to hide the whole table so that
nothing
is shown and the rest of the data moves up. Then carry on down through
the
document repeating the process. I should then have a document that
contains
some pages with a record that has only one table, other records with
maybe
3
tables, etc.

I have never done a Word macro before so some simple tips and steps
would
be
appreciated. Many thanks in advance.






Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cell Reference Between 2 Tables Barb Miles Tables 1 November 21st 06 05:08 AM
How do I stop the automatic addition of another row in Tables? ch Tables 3 October 6th 06 11:51 PM
How to wrap text from cell to cell in a table. Jon Coulson Tables 2 August 8th 05 09:12 PM
Cell references in tables? The Shaker Microsoft Word Help 1 February 28th 05 04:02 PM
Cell shading in Tables KMcLellan Tables 4 December 15th 04 03:36 AM


All times are GMT +1. The time now is 02:07 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"