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!
Klaus Linke - 09 Feb 2007 21:15 GMT
> I'm trying to create a macro that will do the following:
>
[quoted text clipped - 6 lines]
> 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