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 2006

Tip: Looking for answers? Try searching our database.

Macro to change style based on style of current paragraph

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Beth Brooks - 10 Feb 2006 18:50 GMT
Hi!

Though I've made a couple of attempts at this, I have yet to figure out how
to create a macro that does the following.

1. Determine the style of the paragraph in which the cursor is sitting.
2. Compare the style determined in step 1 to a short list of style names. If
the style = A, change the style of the paragraph in which the cursor is
sitting to A1;if the style = B, change to B1, and so on.
3. If the style is not equal to one that is on the list, return an error
message.

ANybody have something liek this I can look at or some suggestions about how
to create this macro?

Thanks!

Beth
Doug Robbins - Word MVP - 10 Feb 2006 19:16 GMT
If the list is not too long, you could use something like

Dim stylename As String
With Selection.Paragraphs(1)
   stylename = .Style
   If stylename = "A" Then
       .Style = "A1"
   ElseIf stylename = "B" Then
       .Style = "B1"
   Else
       MsgBox "Style not in List"
   End If
End With

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi!
>
[quoted text clipped - 17 lines]
>
> Beth
Beth Brooks - 10 Feb 2006 20:47 GMT
Doug,

That worked like a charm. Thanks!

Beth
 
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.