macro for applying one Style conditional on another Style

L

Luanne

I'm trying to create a macro that will do the following:

Let's say I had a table and I applied a certain Style to one of its cells.
I would like for Word to automatically apply a different Style to its
neighboring cell when I tab over. I'm basically trying to translate the
conditional, "If I use Style X in a cell, apply Style Y in the cell to the
right. Otherwise, keep the Style in the cell to the right as Normal." into a
macro. I would appreciate any hints or even websites that will help me do
this. Thanks!
 
K

Klaus Linke

Luanne said:
I'm trying to create a macro that will do the following:

Let's say I had a table and I applied a certain Style to one of its cells.
I would like for Word to automatically apply a different Style to its
neighboring cell when I tab over. I'm basically trying to translate the
conditional, "If I use Style X in a cell, apply Style Y in the cell to the
right. Otherwise, keep the Style in the cell to the right as Normal."
into a
macro. I would appreciate any hints or even websites that will help me do
this. Thanks!


Hi Luanne,

You can highjack the built-in "NextCell" command that runs whenever you use
the Tab key in a table with your own NextCell macro:

Sub NextCell()
Dim myStyle As Style
Set myStyle = Selection.Style
WordBasic.NextCell
Select Case myStyle.NameLocal
Case ActiveDocument.Styles(wdStyleHeading1).NameLocal
Selection.Style = ActiveDocument.Styles(wdStyleHeading2)
Case ActiveDocument.Styles(wdStyleHeading2).NameLocal
Selection.Style = ActiveDocument.Styles(wdStyleHeading3)
Case Else
Selection.Style = ActiveDocument.Styles(wdStyleNormal)
End Select
End Sub

You can highjack the PrevCell command (which runs when you use Shift+Tab)
the same way.

Regards,
Klaus
 

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