G
Gordon Bentley-Mix
OK Kids, here's a fun one for you.
I have a TextBox on a UserForm for collecting the commencement date of a
lease. However, providing a value is optional because the user may not know
commencement date at the time of creating the document. If a value is
provided then this value, properly formatted, is inserted into a bookmark in
the document. And if a value is NOT provided then boilerplate text is
inserted into the bookmark (because in this instance, the user will print the
document and the commencement date will be filled in by hand when the
customer signs the document). All this is simple stuff, and I have it working
with no problems.
HOWEVER...
The client has just added a twist: The bookmark is located in a table cell,
and the client has asked that the cell shading be toggled between "Clear" if
the UserForm value is used and "15% (grey)" if the boilerplate text is used -
ostensibly to call attention to the fact that the commencement date needs to
be entered by hand. Toggling the shading isn't that hard; I can do it using
variations on something like the following sample code (which I banged
together by modifying code generated from the macro recorder):
Sub ShadingTest()
Dim myRange As Range
Set myRange =
ActiveDocument.Bookmarks("txtCommencementDate").Range.Tables(1).Cell(3,
2).Range
With myRange.Shading
.Texture = wdTexture15Percent 'or wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorAutomatic
End With
End Sub
What I'm struggling with is trying to find a way to specify the target cell
based on the "relative location" of the bookmark rather than using the
explicit location of "Cell(3, 2)" or some such. I would prefer this approach
for future-proofing purposes because I'd rather not have to touch the code if
at some point down the line I make some changes to the table that contains
the bookmark (e.g. add some rows before the bookmark or split a cell - which
would totally stuff everything).
Is this even possible? Suggestions on how to do it?
--
Cheers!
Gordon Bentley-Mix
Word MVP
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
I have a TextBox on a UserForm for collecting the commencement date of a
lease. However, providing a value is optional because the user may not know
commencement date at the time of creating the document. If a value is
provided then this value, properly formatted, is inserted into a bookmark in
the document. And if a value is NOT provided then boilerplate text is
inserted into the bookmark (because in this instance, the user will print the
document and the commencement date will be filled in by hand when the
customer signs the document). All this is simple stuff, and I have it working
with no problems.
HOWEVER...
The client has just added a twist: The bookmark is located in a table cell,
and the client has asked that the cell shading be toggled between "Clear" if
the UserForm value is used and "15% (grey)" if the boilerplate text is used -
ostensibly to call attention to the fact that the commencement date needs to
be entered by hand. Toggling the shading isn't that hard; I can do it using
variations on something like the following sample code (which I banged
together by modifying code generated from the macro recorder):
Sub ShadingTest()
Dim myRange As Range
Set myRange =
ActiveDocument.Bookmarks("txtCommencementDate").Range.Tables(1).Cell(3,
2).Range
With myRange.Shading
.Texture = wdTexture15Percent 'or wdTextureNone
.ForegroundPatternColor = wdColorAutomatic
.BackgroundPatternColor = wdColorAutomatic
End With
End Sub
What I'm struggling with is trying to find a way to specify the target cell
based on the "relative location" of the bookmark rather than using the
explicit location of "Cell(3, 2)" or some such. I would prefer this approach
for future-proofing purposes because I'd rather not have to touch the code if
at some point down the line I make some changes to the table that contains
the bookmark (e.g. add some rows before the bookmark or split a cell - which
would totally stuff everything).
Is this even possible? Suggestions on how to do it?
--
Cheers!
Gordon Bentley-Mix
Word MVP
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.