Results 1 to 2 of 2
Thread: BaseStyle bug (Word 2002 SP-2)
2005-03-25, 17:05 #1
- Join Date
- May 2003
- Los Angeles, California, USA
- Thanked 2 Times in 2 Posts
BaseStyle bug (Word 2002 SP-2)
It looks to me like the following line
<pre> Documents("TestBS1.doc").Styles("TargetStyle").Bas eStyle = "DesiredBase"</pre>
will only work if TestBS1.doc is the ActiveDocument. If it's open but AnotherDoc.doc is the ActiveDocument, the BaseStyle setting is changed in AnotherDoc.doc rather than TestBS1.doc. If DesiredBase is not an existing style in AnotherDoc.doc, an error is triggered. If DesiredBase exists in AnotherDoc.doc, no error is triggered (other than the already-noted bug that the code should be operating on TestBS1.doc rather than AnotherDoc.doc).
The same result obtains if "DesiredBase" (on the right of the equal sign) is replaced with the more emphatic Documents("TestBS1.doc").Styles("DesiredBase").
Weirdest of all, if TargetStyle doesn't exist in AnotherDoc.doc, Word creates it (I am not making this up), and then proceeds to set its BaseStyle to DesiredBase. (Probably needless to say, if TestBS1.doc is the ActiveDocument when the same line is run, and if TargetStyle doesn't exist in TestBS1.doc, an error is (appropriately) triggered, rather than Word creating the style.)
Has anybody else dealt with this, or had similar problems trying to create or modify styles in a non-active document? Is there a fix other than making the target document the ActiveDocument?
Bonus question: Does this bug survive in Word 2002 SP-3 and Word 2003?
2005-03-25, 17:39 #2
- Join Date
- Feb 2001
- Silicon Valley, USA
- Thanked 93 Times in 89 Posts
Re: BaseStyle bug (Word 2002 SP-2)
Same in SP3. I used this code to "test" after creating a new TEST style in the inactivedocument:
Dim doc As Word.Document
For Each doc In Application.Documents
If doc.FullName <> MacroContainer.FullName Then
If MsgBox("Change TEST style for " & doc.Name & _
"?", vbQuestion + vbYesNo) = vbYes Then
doc.Styles("TEST").BaseStyle = "Body Text"