Saving styles in Word

V

Vince

Hello,

How can I programmatically show the Style definition in Word? I mean the Tools
- Style & Formatting stuff. I need to be able to show the interface, let the
user create a new style and add it to my template automatically. It would also
suffice if I could store all the style parameters in some file and load it
later (no addition of a style to a template would then be necessary). But, the
latter, I guess must be next to impossible.

TIA,

Vince
 
K

Klaus Linke

Hi Vince,

The dialog to define a new style is a sub-dialog of "FormatStyle", and therefore inaccessible from VBA.
You can show it with SendKeys, but cou can't really use it (say display the dialog, let the user make some settings, and then do whatever you want with those settings).
The "Styles and formatting" task pane is useless for that kind of thing as well.

I'm not sure what you try to do. You could ask your users to check "Add to template" if they define a new style (if your template is the attached template, that is).

Or you could ask your users to use some button to (re)define styles. They'd manually format some paragraph as they want the style to look, and your button could then use WordBasic.RedefineStyle to redefine the style to match that formatting and copy it to your template.

Regards,
Klaus
 
V

Vince

Hey Klaus, Jezebel,

Thank you for your responses. I get the gist of what you are suggesting. I
would like to explain the problem to you for your expert opinion.

The tool I am developing (called Style Manager) is supposed to scan through an
average 40-page document and analyze the various paragraphs. It will then
assign scores to each paragraph (like Bold = 5 points, Italic = 5 points, Font
Size = {Font Size} points and so forth. After the scores are assigned it will
sort the scores in descending order and group the paragraphs into (say) Main
Title, Sub Title and so on. After the tool guesses the groups, I will need to
style each group. This style should be user defined and stored somewhere so
that I can access it during the style process. I initially started with a
Userform with the font size, Initial Lower case, upper case, color, size and
the basic qualities; however, the users would like the style to contain all
fancy things like Hanging indents, numbered lists and so on. I initially
thought of enhancing the form, recording the qualities in a INI file and
loading it later when the style is applied. But it seemed to me that I would
be better off trying to show Word's style dialog, create a style, store it to
the template and call it back when applying it to the paragraphs. This is why
I asked my earlier question. Of course, the word documents the users get have
no existing styles (like Heading 1) and so forth. They are just in the Normal
Style. In case you need to see some snapshot of it please see
http://techotek.com/snp/stylemanager.htm.

Any ideas on this approach? Hope I've explained it clearly this time.

TIA,

Vince
 
K

Klaus Linke

Maybe you can use the dialogs FormatFont and FormatParagraph to get the values.
For a sample, see
http://groups-beta.google.com/group..._frm/thread/1c3d4ed92cf49162/f2d06596ec0e86c4
In Word2003, you'll probably need to .Update the dialog after you .Show it.
You can then use ActiveDocument.Undo to undo the changes that the dialog applied.

In principle, you should be able to just .Display the dialog insted of ..Show it, let the user make the choices, and get the values. But that doesn't work (anymore) with most dialogs.

Regards,
Klaus
 

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