Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2007

Tip: Looking for answers? Try searching our database.

macro for applying one Style conditional on another Style

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Luanne - 09 Feb 2007 20:20 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.