Hi
I am trying create a macro that prompt a message box only if a particular
style has been used in a document.
Below is what I have tried, however, the message box appears regardless if
the style is in use or not:
Dim objStyle As Word.Style
With ActiveDocument
If objStyle.InUse And objStyle.NameLocal = "MyStyle" Then
MsgBox "Incorrect Style in use"
End If
End With
With thanks
Jezebel - 17 Oct 2005 07:32 GMT
First, the code is no good. You haven't set objStyle to refer to anything.
Should be
If ActiveDocument.Styles("MyStyle").InUse then ...
However, this doesn't test whether the style has been applied to anything.
Read Help on the InUse property: "True if the specified style is a built-in
style that has been modified or applied in the document or a new style that
has been created in the document. ... This property doesn't necessarily
indicate whether the style is currently applied to any text in the document.
For instance, if text that's been formatted with a style is deleted, the
InUse property of the style remains True. For built-in styles that have
never been used in the document, this property returns False."
You'll need to use Find, to search for any text with the particular style
applied to it.
> Hi
>
[quoted text clipped - 13 lines]
>
> With thanks
Greg - 17 Oct 2005 13:41 GMT
Sydney,
I am not sure if this will answer you question, but I have a style
report macro on my website that might get you close:
http://gregmaxey.mvps.org/Style_Report.htm
Sydney - 18 Oct 2005 05:23 GMT
Thank you kindly.
> Sydney,
>
> I am not sure if this will answer you question, but I have a style
> report macro on my website that might get you close:
>
> http://gregmaxey.mvps.org/Style_Report.htm