|
-
Jul 5th, 2005, 03:03 PM
#1
Thread Starter
Member
Applying style to docVariable
How do I apply a style to a docVariable?
The scenario is that there is an input form from which the user selects various options. Each option is represented by a docVariable in the active document. If the option is selected, the docVariable value is equal to a certain string. If it is not selected, the docVariable value is equal to " ". ("" Gives me Errors unfortunately).
In a few instances, a style needs to be applied if the option is selected. How do I get at it to apply the style?
-
Jul 5th, 2005, 03:21 PM
#2
Re: Applying style to docVariable
document.. are you working with Word? a webpage? ???
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 6th, 2005, 01:49 PM
#3
Thread Starter
Member
Re: Applying style to docVariable
My apologies. I am working in a Word 2003 document.
-
Jul 7th, 2005, 12:50 PM
#4
Thread Starter
Member
Re: Applying style to docVariable
I thought maybe if I inserted a bookmark to the docVariable in the Word doc I might be able to get at it that way to set the style. But I get the error: "object variable or with block variable not set"
Code:
Dim StyleRng As Range
StyleRng = ActiveDocument.Bookmarks("BMsSig_1Va").Range 'Error here
StyleRng.Style = "Heading 2"
StyleRng.Words(2).Select
Selection.InsertStyleSeparator
-
Jul 7th, 2005, 02:55 PM
#5
Re: Applying style to docVariable
I just tried this.. it worked fine..
Im not using a "range" but it set the Heading 2 style to the first word
ActiveDocument.Words(1).Select
Selection.Style = ActiveDocument.Styles("Heading 2")
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 8th, 2005, 03:33 PM
#6
Thread Starter
Member
Re: Applying style to docVariable
I ended up doing this, which worked, with issues:
Code:
ActiveDocument.Bookmarks("BMsSig_1Va").Select
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.TypeParagraph
Selection.Style = ActiveDocument.Styles("Heading 3")
Selection.MoveRight Unit:=wdCharacter, Count:=23
Selection.InsertStyleSeparator
1. I had to insert the paragraph in the selection rather than including it as part of the string because otherwise the style was applied to the preceding paragraph where the return was placed as that is where the docVariable bringing in the text which is bookmarked is located. I will probably insert yet another docVariable that will be set to a return if that option is set because if the option is then changed to something else, the return should not be there nor the style applied.
2. The InsertStyleSeparator did not insert a style separator. I'm not sure if this doesn't work when the selection is a docVariable or what the reason would be, but I guess that's another post. For the time being I think I can work around it by splitting the docVariable into, yet again, 2 docVariables and inserting the StyleSeparator between them.
-
Jul 11th, 2005, 12:49 PM
#7
Thread Starter
Member
Re: Applying style to docVariable
For some reason the numbering for the style does not apply when the paragraph return is in through Chr(13) or VbCrLf or anything else in a docVariable. I only see the numbering apply when I do
Selection.TypeParagraph
Any ideas?
This then leaves me having to test for the paragraph if the control box that generates the paragraph is unchecked, which seems most inefficient.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|