Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

MS Word Font Color and Bullets/Numberings

145 views
Skip to first unread message

James

unread,
Jun 26, 2004, 8:09:47 PM6/26/04
to
Hi, All:

Any expert knows:

1) How to set WordDocument selection's font color? I tried
Doc.Application.Selection.Font.ColorIndex := clRed. It would not work. I
can not find a Font.Color property in Word97.

2) Also how to automate selection format with Bullets/Numberings?
There is no this property in paragraphs.

Thanks.

James


Oliver Townshend

unread,
Jun 26, 2004, 8:42:57 PM6/26/04
to
> 1) How to set WordDocument selection's font color? I tried
> Doc.Application.Selection.Font.ColorIndex := clRed. It would not work. I
> can not find a Font.Color property in Word97.

You need to read the Word VBA Help Files:

WdColorIndex can be one of these WdColorIndex constants.
wdAuto
wdBlack
wdBlue
wdBrightGreen
wdByAuthor
wdDarkBlue
wdDarkRed
wdDarkYellow
wdGray25
wdGray50
wdGreen
wdNoHighlight
wdPink
wdRed
wdTeal
wdTurquoise
wdViolet
wdWhite
wdYellow

> 2) Also how to automate selection format with Bullets/Numberings?
> There is no this property in paragraphs.

No, its a property of a Range. The simplest way to find out what you need
to automate is to record a macro that does what you want and look at the
subsequent VBA code. If you did, you would see something like:

With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
.NumberFormat = "%1."
.TrailingCharacter = wdTrailingTab
.NumberStyle = wdListNumberStyleArabic
.NumberPosition = CentimetersToPoints(0.63)
.Alignment = wdListLevelAlignLeft
.TextPosition = CentimetersToPoints(1.27)
.TabPosition = CentimetersToPoints(1.27)
.ResetOnHigher = 0
.StartAt = 1
With .Font
.Bold = wdUndefined
.Italic = wdUndefined
.StrikeThrough = wdUndefined
.Subscript = wdUndefined
.Superscript = wdUndefined
.Shadow = wdUndefined
.Outline = wdUndefined
.Emboss = wdUndefined
.Engrave = wdUndefined
.AllCaps = wdUndefined
.Hidden = wdUndefined
.Underline = wdUndefined
.Color = wdUndefined
.Size = wdUndefined
.Animation = wdUndefined
.DoubleStrikeThrough = wdUndefined
.Name = ""
End With
.LinkedStyle = ""
End With
ListGalleries(wdNumberGallery).ListTemplates(1).Name = ""
Selection.Range.ListFormat.ApplyListTemplate
ListTemplate:=ListGalleries( _
wdNumberGallery).ListTemplates(1), ContinuePreviousList:=False,
ApplyTo:= _
wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior

Oliver Townshend


James

unread,
Jun 26, 2004, 10:55:06 PM6/26/04
to
Just some feedback: I am able to get the bullets working by using default
parameter:

Range.ListFormat.ApplyBulletDefault;

but failed at importing recorded Macro -- I can not find a Delphi
equivalent of ChrW function for:

NumberFormat := ChrW(61607)

James.

"Oliver Townshend" <oliver_at_zip_com_au> wrote in message
news:40de...@newsgroups.borland.com...

Oliver Townshend

unread,
Jun 26, 2004, 11:21:57 PM6/26/04
to
> NumberFormat := ChrW(61607)

Go in to VBA Editor inside Word, pull up the Instant window and type
?Chrw(61607) which will tell you the value of that function.

Oliver Townshend


James

unread,
Jun 26, 2004, 11:38:15 PM6/26/04
to
Thanks, Oliver:

VBA gave out a question mark '?' for ChrW(61607). I think this usually
means non-printable character. I plug this in Delphi. It generates very
funny looking bullets. On the better end, it no longer causes "out of
range" error.

James


"Oliver Townshend" <oliver_at_zip_com_au> wrote in message
news:40de...@newsgroups.borland.com...

James

unread,
Jun 26, 2004, 11:43:50 PM6/26/04
to
By the way, here is the ported code:

procedure TForm1.btnBulletsClick(Sender: TObject);
var
vListTemplate: ListTemplate;
vLevel: OleVariant;
OutlineNum: OleVariant;
Level: ListLevel;
ContinuePrev: OleVariant;
begin
WordDocument1.Select;

WordDocument1.Application.Selection.TypeText('a');
WordDocument1.Application.Selection.TypeParagraph;
WordDocument1.Application.Selection.TypeText('b');

WordDocument1.Application.ActiveDocument.Select;

OutLineNum := True;
vListTemplate := WordDocument1.ListTemplates.Add(OutLineNum, EmptyParam);

Level := vListTemplate.ListLevels.Item(1);

Level.NumberFormat := '?'; //ChrW(61607);
Level.TrailingCharacter := wdTrailingTab;
Level.NumberStyle := wdListNumberStyleBullet;
Level.Alignment := wdListLevelAlignLeft;

Level.Font.Bold := wdUndefined;
Level.Font.Italic := wdUndefined;
Level.Font.StrikeThrough := wdUndefined;
Level.Font.Subscript := wdUndefined;
Level.Font.Superscript := wdUndefined;
Level.Font.Shadow := wdUndefined;
Level.Font.Outline := wdUndefined;
Level.Font.Emboss := wdUndefined;
Level.Font.Engrave := wdUndefined;
Level.Font.AllCaps := wdUndefined;
Level.Font.Hidden := wdUndefined;
Level.Font.Underline := wdUndefined;
Level.Font.ColorIndex := wdUndefined;
Level.Font.Size := 10;
Level.Font.Animation := wdUndefined;
Level.Font.DoubleStrikeThrough := wdUndefined;
Level.Font.Name := 'Wingdings';

Level.LinkedStyle := '';

ContinuePrev := False;
WordDocument1.Range.ListFormat.ApplyListTemplate(vListTemplate,
ContinuePrev, EmptyParam); //wdListApplyToWholeList);

end;


"James" <NoSpamJ...@sympatico.ca> wrote in message

Oliver Townshend

unread,
Jun 27, 2004, 12:10:14 AM6/27/04
to
> VBA gave out a question mark '?' for ChrW(61607). I think this
usually
> means non-printable character. I plug this in Delphi. It generates very
> funny looking bullets. On the better end, it no longer causes "out of
> range" error.

Looking in the help file is see that ChrW is a Character Wide function. So
there should be an equivalent in Delphi (although I can't find it). I'm
surprised Word 97 cares about this. Did you work from my code? Because I
ran Word 2003 to generate the code. Maybe you should run Word 97 and check
what it generates.

Oliver Townshend


James

unread,
Jun 27, 2004, 12:20:43 AM6/27/04
to
Hi, Oliver:

I generated the code from Word 97 with the macro recording method you
suggested. And then removed a few of those properties causing error in
Delphi. Word seems to like to use those strange characters (rather than
image), for the speed purpose I guess. Other than the look of bullet
itself. The code does work though.

Also do you (or anyone else) happen to know a Word color picker
component?

Thanks again.

Wanli


"Oliver Townshend" <oliver_at_zip_com_au> wrote in message
news:40de...@newsgroups.borland.com...

Oliver Townshend

unread,
Jun 27, 2004, 12:25:36 AM6/27/04
to
> Also do you (or anyone else) happen to know a Word color picker
> component?

There's one on the toolbar. Are you automating inside or outside of Word?

Oliver Townshend


James

unread,
Jun 27, 2004, 12:32:41 AM6/27/04
to
The following code works but it uses default. Automation has no control
over bullet style.

procedure TForm1.Button1Click(Sender: TObject);
var
ListFmt: ListFormat;
ContinueList: OleVariant;
begin
ListFmt := WordDocument1.Application.Selection.Range.ListFormat;
ListFmt.ApplyBulletDefault;
ContinueList := False;
ListFmt.ApplyListTemplate(ListFmt.ListTemplate, ContinueList, EmptyParam);
end;

James

"Oliver Townshend" <oliver_at_zip_com_au> wrote in message
news:40de...@newsgroups.borland.com...

James

unread,
Jun 27, 2004, 12:34:37 AM6/27/04
to
I use TWebBrowser control.


"Oliver Townshend" <oliver_at_zip_com_au> wrote in message
news:40de...@newsgroups.borland.com...

Oliver Townshend

unread,
Jun 27, 2004, 1:15:50 AM6/27/04
to
> I use TWebBrowser control.

I can't really help you then, most of my work is in VBA macros and Delphi
Add-ins.

Oliver Townshend


James

unread,
Jun 27, 2004, 1:32:33 AM6/27/04
to
You are already a great help by pointing to the macro recording. Never
thought about borrowing idea from there before. Thanks.

I also do some Office automation in pure VB. But I more like automation
with Delphi via either OLE container or WebBrowser. There is less
security/virus issue for one. There are disadvantages though: OLE
container menu merge is a mess. Yet with WebBrowser, all menu/tool bars are
lost.

James

"Oliver Townshend" <oliver_at_zip_com_au> wrote in message
news:40de...@newsgroups.borland.com...

0 new messages