B
Bear
Here's the application. I'm building a Find and Replace dialog box, but one
that just works on styles.
For the Find list, it's easy to get the styles in use from the active
document.
The Replace list is supposed to come from the template attached to the
document.
So the idea is you can find any style in the document, but you can only
replace them with "valid" styles as defined in the template.
To get the styles from the attached template ... That's the problem. I have
to avoid creating a new document from the target template, as that will
trigger the ThisDocument > New processing.
Here's what I finally settled on.
Set objTemplate = Documents.Add( _
Template:=NormalTemplate.FullName, _
DocumentType:=wdNewBlankDocument, _
Visible:=False)
objTemplate.CopyStylesFromTemplate (ActiveDocument.AttachedTemplate.FullName)
For Each objStyle In objTemplate.Styles
If objStyle.InUse = True Then
Me.cboWithStyleName.AddItem (objStyle.NameLocal)
End If
Next objStyle
objTemplate.Close savechanges:=wdDoNotSaveChanges
The idea is to create a new document from Normal.dot (which has no
ThisDocument > New code) and copy the styles from the target active document
into the new document. Then I load the styles from that document into the
list and close the dummy document.
BUT
For some reason when Visible:=False, the ThisDocument > New processing for
the target document runs anyway! Try it. You'll see.
Anybody know how to avoid this? Anybody know a slicker way of getting a list
of the style names from the active document's attached template?
Bear
that just works on styles.
For the Find list, it's easy to get the styles in use from the active
document.
The Replace list is supposed to come from the template attached to the
document.
So the idea is you can find any style in the document, but you can only
replace them with "valid" styles as defined in the template.
To get the styles from the attached template ... That's the problem. I have
to avoid creating a new document from the target template, as that will
trigger the ThisDocument > New processing.
Here's what I finally settled on.
Set objTemplate = Documents.Add( _
Template:=NormalTemplate.FullName, _
DocumentType:=wdNewBlankDocument, _
Visible:=False)
objTemplate.CopyStylesFromTemplate (ActiveDocument.AttachedTemplate.FullName)
For Each objStyle In objTemplate.Styles
If objStyle.InUse = True Then
Me.cboWithStyleName.AddItem (objStyle.NameLocal)
End If
Next objStyle
objTemplate.Close savechanges:=wdDoNotSaveChanges
The idea is to create a new document from Normal.dot (which has no
ThisDocument > New code) and copy the styles from the target active document
into the new document. Then I load the styles from that document into the
list and close the dummy document.
BUT
For some reason when Visible:=False, the ThisDocument > New processing for
the target document runs anyway! Try it. You'll see.
Anybody know how to avoid this? Anybody know a slicker way of getting a list
of the style names from the active document's attached template?
Bear