Referring to Macrobutton Field properties without selecting them

J

JuanManuel

Is it possible to refer in code to Macrobutton fields in order to modify
their properties.

If so, how??

Just in case, let me provide the specific example. I currently have a
document with more than 200 tables. Each table has in its top row a
Macrobutton field that hides and unhides the rows from row 2 to the last one.
Furthermore, when the table is hidden, the macrobutton field becomes green if
the table is empty and red if there is something in any cell of the table.
When the table is unhidden the macrobutton is blue. Everyting I just
described is already implemented (I provide it just as a background).

What I'm planning to do now is, using another button (either activeX or
macrobutton) placed at the top of the document, to hide or unhide all the
tables in the document at once and format each of the macrobutton in each
table accordingly.

I already wrote the code of this top button and it does hide or unhide all
the tables in the document. The only problem is that it does not change the
background color of the macrobuttons in each table.

Can this be accomplished?
 
M

macropod

Hi Juan,

I'd suggest using a loop to test the contents of each table before hiding and changing the Macrobutton field colours then.

The alternative would be to programmatically trigger each macrobutton to hide its table and use the existing code to determine the
colour. Doing it that way might be somewhat slower, though.
 
J

JuanManuel

Hi macropod,

Thanks for your response. What you suggested is exactly what I am doing
(using a loop to test the contents of each table before hiding and changing
the Macrobutton field colours). It is working fine, but it is taking a while.

I guess my question would have been more accurate like this: Can I refer to
Macrobutton field properties directly (i.e., not using the range object). An
extract of my code looks like this:


Set RngMacrobutton = TheMiniTable.Rows(1).Cells(10).Range
With RngMacrobutton
With .Font
.Color = wdColorAutomatic
With .Shading
.Texture = wdTextureNone
.BackgroundPatternColor = wdColorRed
End With
End With
End With

Since I know that the macrobutton for each table is located in row 1 and
column 10 I just use the above code. I have to use the range object as you
can see.

Although you say that the second method you suggested (to programmatically
trigger each macrobutton to hide its table and use the existing code to
determine the colour) might be slower, I'd like to give it a try.

For that purpose though, I have no clue as to waht the code would look like
to programatically trigger each macrobutton. Could you help me with this??
Would I still have to use the range object at which each macrobutton is
located?

Thank you,

Juan M. Lemus


macropod said:
Hi Juan,

I'd suggest using a loop to test the contents of each table before hiding and changing the Macrobutton field colours then.

The alternative would be to programmatically trigger each macrobutton to hide its table and use the existing code to determine the
colour. Doing it that way might be somewhat slower, though.

--
Cheers
--
macropod
[MVP - Microsoft Word]


JuanManuel said:
Is it possible to refer in code to Macrobutton fields in order to modify
their properties.

If so, how??

Just in case, let me provide the specific example. I currently have a
document with more than 200 tables. Each table has in its top row a
Macrobutton field that hides and unhides the rows from row 2 to the last one.
Furthermore, when the table is hidden, the macrobutton field becomes green if
the table is empty and red if there is something in any cell of the table.
When the table is unhidden the macrobutton is blue. Everyting I just
described is already implemented (I provide it just as a background).

What I'm planning to do now is, using another button (either activeX or
macrobutton) placed at the top of the document, to hide or unhide all the
tables in the document at once and format each of the macrobutton in each
table accordingly.

I already wrote the code of this top button and it does hide or unhide all
the tables in the document. The only problem is that it does not change the
background color of the macrobuttons in each table.

Can this be accomplished?
 
M

macropod

Hi Juan,

I'm confused. In your previous post, you said "The only problem is that it does not change the background color of the macrobuttons
in each table". Now you you're saying "It is working fine, but it is taking a while".

With 200 tables to process, I'm not surprised that it takes some time. Three things you could do to speed up processing are to
temporarily switch off:
1. screen updating (Application.ScreenUpdating = False)
2. change tracking (ActiveDocument.TrackRevisions = False)
3. automatic column widths for the tables (TheMiniTable.AllowAutoFit = False, or TheMiniTable.AutoFitBehavior wdAutoFitFixed)
The last is particularly effective if what you're doing might change the column widths.

To programmatically trigger each macrobutton, you could use the fields collection, testing whether the field is a macrobutton field.
For example:
Sub Trigger()
Dim oFld As Field
For Each oFld In ActiveDocument.Fields
If oFld.Type = wdFieldMacroButton Then oFld.DoClick
Next
End Sub

--
Cheers
--
macropod
[MVP - Microsoft Word]


JuanManuel said:
Hi macropod,

Thanks for your response. What you suggested is exactly what I am doing
(using a loop to test the contents of each table before hiding and changing
the Macrobutton field colours). It is working fine, but it is taking a while.

I guess my question would have been more accurate like this: Can I refer to
Macrobutton field properties directly (i.e., not using the range object). An
extract of my code looks like this:


Set RngMacrobutton = TheMiniTable.Rows(1).Cells(10).Range
With RngMacrobutton
With .Font
.Color = wdColorAutomatic
With .Shading
.Texture = wdTextureNone
.BackgroundPatternColor = wdColorRed
End With
End With
End With

Since I know that the macrobutton for each table is located in row 1 and
column 10 I just use the above code. I have to use the range object as you
can see.

Although you say that the second method you suggested (to programmatically
trigger each macrobutton to hide its table and use the existing code to
determine the colour) might be slower, I'd like to give it a try.

For that purpose though, I have no clue as to waht the code would look like
to programatically trigger each macrobutton. Could you help me with this??
Would I still have to use the range object at which each macrobutton is
located?

Thank you,

Juan M. Lemus


macropod said:
Hi Juan,

I'd suggest using a loop to test the contents of each table before hiding and changing the Macrobutton field colours then.

The alternative would be to programmatically trigger each macrobutton to hide its table and use the existing code to determine
the
colour. Doing it that way might be somewhat slower, though.

--
Cheers
--
macropod
[MVP - Microsoft Word]


JuanManuel said:
Is it possible to refer in code to Macrobutton fields in order to modify
their properties.

If so, how??

Just in case, let me provide the specific example. I currently have a
document with more than 200 tables. Each table has in its top row a
Macrobutton field that hides and unhides the rows from row 2 to the last one.
Furthermore, when the table is hidden, the macrobutton field becomes green if
the table is empty and red if there is something in any cell of the table.
When the table is unhidden the macrobutton is blue. Everyting I just
described is already implemented (I provide it just as a background).

What I'm planning to do now is, using another button (either activeX or
macrobutton) placed at the top of the document, to hide or unhide all the
tables in the document at once and format each of the macrobutton in each
table accordingly.

I already wrote the code of this top button and it does hide or unhide all
the tables in the document. The only problem is that it does not change the
background color of the macrobuttons in each table.

Can this be accomplished?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top