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 / May 2004

Tip: Looking for answers? Try searching our database.

macros for styles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MALA - 28 May 2004 20:30 GMT
I am trying to create a macro where it checks all the
templates styles with extra styles and displays which are
not matching with the template styles.

eg. I have template where there are 5 styles and people
are suppose to use those only. If they copy paste they are
bringing styles from outside. So, when they click the
buttone it should say these styles are not matching.

Any help!!!

thanks
MALA
Charles Kenyon - 28 May 2004 20:46 GMT
Version of Word you are using?

> I am trying to create a macro where it checks all the
> templates styles with extra styles and displays which are
[quoted text clipped - 9 lines]
> thanks
> MALA
- 31 May 2004 14:24 GMT
Word 2000
>-----Original Message-----
>Version of Word you are using?
[quoted text clipped - 14 lines]
>
>.
Klaus Linke - 31 May 2004 18:02 GMT
> bringing styles from outside. So, when they click the
> buttone it should say these styles are not matching.

Hi Mala,

The macro below will check for styles that aren't defined in the attached
template.
One thing that may not be obvious is that you need to actually open the
template to get at the styles in the template.

The macro works by raising an error if a style from the doc isn't defined
in the template... this is faster than looping all styles in the template,
looking for the one defined in the document.

The macro could be improved in several ways (don't show the opened template
on screen; add error handlers if no template is attached, or if the
attached template can't be opened; create a list instead of showing
multiple message boxes ...)

Another thing you may want to change: The macro tests all styles in the
document.
Maybe you don't want to check built-in styles, or styles that aren't used?

Regards,
Klaus

Sub TestIfStylesInDot()

On Error GoTo ErrHandler
Dim styleLoop As style
Dim docOpen As Document
Set docOpen = ActiveDocument
Dim docTemplateAttached As Document
Set docTemplateAttached = _
 docOpen.AttachedTemplate.OpenAsDocument

' just used to raise an error if style isn't in template:
Dim boolDummy As Boolean

' check all styles in the document
For Each styleLoop In docOpen.Styles
 StatusBar = "Checking " & styleLoop.NameLocal
 ' If styleLoop isn't in the template, the ErrHandler will kick in:
 boolDummy = docTemplateAttached.Styles(styleLoop.NameLocal).InUse
Next styleLoop
docTemplateAttached.Close SaveChanges:=False
docOpen.Activate
Exit Sub

ErrHandler:

 If MsgBox(styleLoop.NameLocal, vbOKCancel, _
  "Style not in Template:") = vbCancel Then
   docTemplateAttached.Close SaveChanges:=False
   docTemplateAttached.Close SaveChanges:=False
   docOpen.Activate
   Exit Sub
 End If
 Err.Clear
 Resume Next

End Sub
 
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.