Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Marrick13
 
Posts: n/a
Default Need macro to locate table uniquely, insert blank row and date and end table

I have a Word template that contains one table of 1-4 rows and 4 columns (the
table is to record the document's revision history). I have a macro that
inserts a blank row and the current date in the first column of that row, but
if I run the macro again, the date goes outside the table. The macro is
executed as an AutoNew command so that it runs as soon as a document is
created from the template. It works fine for that one-time run at document
creation.

However, once the new document has been created, there will be a need to run
a macro to insert a blank row in the same table. If this macro is run twice,
it puts the date outside the table because the cursor is still in the table.
Also, there may be another one or more tables in the document when it is
edited, and I would prefer to have the macro locate only that table by some
unique identifier, such as a bookmark. I've seen code that locates tables
according to specific text as well as the first table in a document (as shown
below), but I have not been able to determine if there is a way to find a
table uniquely.

The row insertion code is:

ActiveDocument.Tables(1).Rows.Add
rownum = ActiveDocument.Tables(1).Rows.Count

Date insertion code is:

Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern, _
InsertAsFullWidth:=False

So, can someone help me with a macro that will:

1. Find a table by a unique identifier
2. Insert a blank row at the end and the current date in its first column
3. Be able to do 1 and 2 more than once in a document created from a template.


Thank you.
  #2   Report Post  
Posted to microsoft.public.word.tables
Jezebel
 
Posts: n/a
Default Need macro to locate table uniquely, insert blank row and date and end table

Use a bookmark to identify the table (ie open the template, select the
table, define a bookmark).

With ActiveDocument.Bookmarks("DocHistory").Range.Table s(1)
.Rows.Add
.Cell(.Rows.Count, 1) = format(Now, "yyyy-mm-dd")
End with







"Marrick13" u23626@uwe wrote in message news:628eeba077608@uwe...
I have a Word template that contains one table of 1-4 rows and 4 columns
(the
table is to record the document's revision history). I have a macro that
inserts a blank row and the current date in the first column of that row,
but
if I run the macro again, the date goes outside the table. The macro is
executed as an AutoNew command so that it runs as soon as a document is
created from the template. It works fine for that one-time run at
document
creation.

However, once the new document has been created, there will be a need to
run
a macro to insert a blank row in the same table. If this macro is run
twice,
it puts the date outside the table because the cursor is still in the
table.
Also, there may be another one or more tables in the document when it is
edited, and I would prefer to have the macro locate only that table by
some
unique identifier, such as a bookmark. I've seen code that locates tables
according to specific text as well as the first table in a document (as
shown
below), but I have not been able to determine if there is a way to find a
table uniquely.

The row insertion code is:

ActiveDocument.Tables(1).Rows.Add
rownum = ActiveDocument.Tables(1).Rows.Count

Date insertion code is:

Selection.InsertDateTime DateTimeFormat:="MMMM d, yyyy", InsertAsField:= _
False, DateLanguage:=wdEnglishUS, CalendarType:=wdCalendarWestern,
_
InsertAsFullWidth:=False

So, can someone help me with a macro that will:

1. Find a table by a unique identifier
2. Insert a blank row at the end and the current date in its first column
3. Be able to do 1 and 2 more than once in a document created from a
template.


Thank you.



  #3   Report Post  
Posted to microsoft.public.word.tables
Marrick13 via OfficeKB.com
 
Posts: n/a
Default Need macro to locate table uniquely, insert blank row and date and end table

Thank you, Jezebel. Only trouble is that I get a compile error with "Invalid
use of property" message on the .Cell(.Rows.Count, 1) = format(Now, "yyyy-mm-
dd") line. I don't understand the property well enough to debug, can you
assist?

Jezebel wrote:
Use a bookmark to identify the table (ie open the template, select the
table, define a bookmark).

With ActiveDocument.Bookmarks("DocHistory").Range.Table s(1)
.Rows.Add
.Cell(.Rows.Count, 1) = format(Now, "yyyy-mm-dd")
End with

I have a Word template that contains one table of 1-4 rows and 4 columns
(the

[quoted text clipped - 42 lines]

Thank you.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...ables/200607/1
  #4   Report Post  
Posted to microsoft.public.word.tables
Jezebel
 
Posts: n/a
Default Need macro to locate table uniquely, insert blank row and date and end table

My mistake. Should be

.Cell(.Rows.Count, 1).Range = format(Now, "yyyy-mm-dd")


"Marrick13 via OfficeKB.com" u23626@uwe wrote in message
news:62933cbd2ab5c@uwe...
Thank you, Jezebel. Only trouble is that I get a compile error with
"Invalid
use of property" message on the .Cell(.Rows.Count, 1) = format(Now,
"yyyy-mm-
dd") line. I don't understand the property well enough to debug, can you
assist?

Jezebel wrote:
Use a bookmark to identify the table (ie open the template, select the
table, define a bookmark).

With ActiveDocument.Bookmarks("DocHistory").Range.Table s(1)
.Rows.Add
.Cell(.Rows.Count, 1) = format(Now, "yyyy-mm-dd")
End with

I have a Word template that contains one table of 1-4 rows and 4 columns
(the

[quoted text clipped - 42 lines]

Thank you.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...ables/200607/1



  #5   Report Post  
Posted to microsoft.public.word.tables
Marrick13 via OfficeKB.com Marrick13 via OfficeKB.com is offline
external usenet poster
 
Posts: 7
Default Need macro to locate table uniquely, insert blank row and date and end table

Jezebel,
That did the trick. Thanks so much!!

Jezebel wrote:
My mistake. Should be

.Cell(.Rows.Count, 1).Range = format(Now, "yyyy-mm-dd")

Thank you, Jezebel. Only trouble is that I get a compile error with
"Invalid

[quoted text clipped - 16 lines]

Thank you.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...ables/200607/1
Reply
Thread Tools
Display Modes

Posting Rules

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

Forum Jump


All times are GMT +1. The time now is 03:45 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"