Creating a Blank Style?

B

bhartman36

Hi, Everyone.

I'm trying to simplify creating a table of contents for my documents.
I've got a font setup for my documents that I like, so I don't want a
style to mess with it. Unfortunately, when I create a new style
using:

ActiveDocument.Styles.Add ("macrotoc")

the style it creates isn't blank. I would like a style to be created
that keeps all the text within the style the same as it was before the
style was applied (e.g., things that are bolded stay bolded, underline
stays underlined, non-bold stays non-bold, etc.). Is there a way to
specify that the style is blank in this way??

Thanks!
 
J

Jean-Guy Marcil

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :
Hi, Everyone.

I'm trying to simplify creating a table of contents for my documents.
I've got a font setup for my documents that I like, so I don't want a
style to mess with it. Unfortunately, when I create a new style

This is why you should have used styles from the get go...
using:

ActiveDocument.Styles.Add ("macrotoc")

the style it creates isn't blank. I would like a style to be created
that keeps all the text within the style the same as it was before the
style was applied (e.g., things that are bolded stay bolded, underline
stays underlined, non-bold stays non-bold, etc.). Is there a way to
specify that the style is blank in this way??

In short, no.

Although you do no mention it, am I correct in thinking that you want to
create a style and then apply it to the paragraphs that will be used to
create a TOC?

If using style after the fact is too messy for you, you can use TC fields
instead:

Select the text to be used in the TOC, let's say "Chapter 1"
Do CTRL-C (Copy)
Place the cursor immediately before the selected text
DO CTRL-V (Paste)
You should now have: "Chapter 1Chapter 1"
Select this newly pasted text and do CTRL-F9
This will create a pair of field delimiters around the selected text
{ Chapter 1 }
Complete the field like so:
{ TC "Chapter 1" } (If the text has spaces, you need the "")
As soon as you do that, the field becomes a hidden text field
Now repeat for all your TOC entries
Create the TOC by doing CTRL-F9 where you want the TOC:
{}
Complete the field:
{ TOC \f }
Select the field and do F9 to toggle and update at the same time.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
B

bhartman36

(e-mail address removed) was telling us:
(e-mail address removed) nous racontait que :



This is why you should have used styles from the get go...




In short, no.

Although you do no mention it, am I correct in thinking that you want to
create a style and then apply it to the paragraphs that will be used to
create a TOC?

If using style after the fact is too messy for you, you can use TC fields
instead:

Select the text to be used in the TOC, let's say "Chapter 1"
Do CTRL-C (Copy)
Place the cursor immediately before the selected text
DO CTRL-V (Paste)
You should now have: "Chapter 1Chapter 1"
Select this newly pasted text and do CTRL-F9
This will create a pair of field delimiters around the selected text
{ Chapter 1 }
Complete the field like so:
{ TC "Chapter 1" } (If the text has spaces, you need the "")
As soon as you do that, the field becomes a hidden text field
Now repeat for all your TOC entries
Create the TOC by doing CTRL-F9 where you want the TOC:
{}
Complete the field:
{ TOC \f }
Select the field and do F9 to toggle and update at the same time.

--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:http://www.word.mvps.org

Hi, Jean-Guy.

Thanks for the help! The reason I didn't create the style first is
that I'm working with a file exported from another program (EndNote)
so I have to work with what I'm given. I was actually able to solve
my problem, though. Here's what I did. (I'm not at my work computer
right now, so I might not be remembering the code exactly right):

ActiveDocument.Styles("macrotoc").Add
With ActiveDocument.Styles("macrotoc")
..Font.Size="10"
..Font.Name="Arial"
End With


With that (and some code to make sure that the style doesn't already
exist), I'm able to change just the size and the font. The only
caveat is that for some reason I have to select both the paragraph and
the paragraph mark *before* that paragraph. Kind of weird, but it
works as long as I stay in "Reveal Codes" mode when I do it.

I'm going to try out your method in my next project, though, because
it seems a lot easier. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top