Return Values of Application.Dialogs(wdDialogFormatDefineStyleFont)?

O

Oliverm

Dear all

I made an macro that opens the "format -> Characters" dialog
"wdDialogFormatDefineStyleFont". See below.

Unfortunately, I haven't figured out how the receive the return values
such as style, font, color, ... my aim is to format a text field of a
form - and later a text in word - with those parameters.

I can return the color as a two digit number. E.g black would be 01.
Unfortunately, this is obviuously something different from what
ForeColor is expecting.

My somebody lend me an helping hand? Suggestions and tips are very
welcome too.

Kind Regards
Oliver




(Same posting in microsoft.public.de.word)




Code:
-----------------
Function getColor() As Integer

' Thanks to http://www.tech-archive.net/Archive/Word/microsoft.public.word.vba.general/2006-11/msg00416.html

Dim MyFontDlg As Dialog
Static MyFontColor
Static MyFontStyle
Dim res

Set MyFontDlg = Application.Dialogs(wdDialogFormatDefineStyleFont)
MyFontDlg.Color = MyFontColor


res = MyFontDlg.Display

MyFontColor = MyFontDlg.Color


Debug.Print ("Font Color:" & MyFontColor)


getColor = MyFontColor


End Function
 
J

Jay Freedman

Documentation of the dialog arguments is (and always has been) extremely
poor. Experiment shows, though, that the .Color argument of the
wdDialogFormatDefineStyleFont dialog and the similar wdDialogFormatFont
dialog is an integer that gets and sets values in the wdColorIndex
enumeration -- for which there are only 16 values.

However, the dialogs also have a .ColorRGB argument. This is a Long data
type that gets and sets all possible color choices, including those from the
"More Colors" palette. These are the numbers you're looking for. In your
macro, replace MyFontDlg.Color with MyFontDlg.ColorRGB in two places.

If you plan to use the function's value in other code, also change the
function declaration from Integer to Long. Also, for efficiency it would be
a good idea to declare MyFontColor as a Long and remove the declaration of
MyFontStyle.

Although the values appear to be just "big numbers" when displayed in
decimals, they actually correspond to the red, green, and blue components
expressed as hexadecimal values. The low-order (rightmost) two hex digits
are the red component, the middle pair are the green, and the high-order
(leftmost) pair are the blue. For example, if you choose the color labeled
"Plum" in the dialog, the RGB value appears as the decimal number 6697881.
This is equivalent to the hex number 663399, which is hex 66 (decimal 102)
blue, hex 33 (decimal 51) green, and hex 99 (decimal 153) red. In the
Debug.Print statement, you could print Hex(MyFontColor) instead of the
decimal value.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
O

Oliverm

...
However, the dialogs also have a .ColorRGB argument. This is a Long data
type that gets and sets all possible color choices, including those from the
"More Colors" palette. These are the numbers you're looking for. In your
macro, replace MyFontDlg.Color with MyFontDlg.ColorRGB in two places.

If you plan to use the function's value in other code, also change the
function declaration from Integer to Long. Also, for efficiency it would be
a good idea to declare MyFontColor as a Long and remove the declaration of
MyFontStyle.

Although the values appear to be just "big numbers" when displayed in
decimals, they actually correspond to the red, green, and blue components
expressed as hexadecimal values. The low-order (rightmost) two hex digits
are the red component, the middle pair are the green, and the high-order
(leftmost) pair are the blue. For example, if you choose the color labeled
"Plum" in the dialog, the RGB value appears as the decimal number 6697881.
This is equivalent to the hex number 663399, which is hex 66 (decimal 102)
blue, hex 33 (decimal 51) green, and hex 99 (decimal 153) red. In the
Debug.Print statement, you could print Hex(MyFontColor) instead of the
decimal value.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Hello Jay

Thank you for your kind explenation and the hints with the color
conversation.
If I got it right I have a pattern for RGB like "RRRGGGBBB"; each from
0 to 255.. and furthermore, I need the hex-Values to color a text
field in a form.

I've changed my code to something simpler to debug and learn. (See
below).

Do you probably know, where I could find a reference of the parameters
of wdDialogFormatDefineStyleFont?
I figured out color, font, type but would like to become familiar with
all parameters. Unfortunately I couldn't find any reference in the
web. Is there a way to receive all parameters in one go as an array
(or s.t similar)?

Regards,
Oliver

Code:
------------

Function getAttribs() As Long

With Application.Dialogs(wdDialogFormatDefineStyleFont)
MsgBox .Display & " Display"
MsgBox .ColorRGB & " Color"
MsgBox .Type & " Type"
MsgBox .Font & " Font"
End With

'return

End Function
 
O

Oliverm

...
Hello Jay

Thank you for your kind explenation and the hints with the color
conversation.
If I got it right I have a pattern for RGB like "RRRGGGBBB"; each from
0 to 255.. and furthermore, I need the hex-Values to color a text
field in a form.
...

Just to complete the picture: I figured out, that it works finde with
the RGB value. No need to convert into HEX.
...buuut, I'd be still looking for the remaining parameters of
wdDialogFo­rmatDefineStyleFont ...

Regards,
Oliver
 
J

Jay Freedman

Oliverm said:
...

Hello Jay

Thank you for your kind explenation and the hints with the color
conversation.
If I got it right I have a pattern for RGB like "RRRGGGBBB"; each from
0 to 255.. and furthermore, I need the hex-Values to color a text
field in a form.

I've changed my code to something simpler to debug and learn. (See
below).

Do you probably know, where I could find a reference of the parameters
of wdDialogFormatDefineStyleFont?
I figured out color, font, type but would like to become familiar with
all parameters. Unfortunately I couldn't find any reference in the
web. Is there a way to receive all parameters in one go as an array
(or s.t similar)?

Regards,
Oliver

Code:
------------

Function getAttribs() As Long

With Application.Dialogs(wdDialogFormatDefineStyleFont)
MsgBox .Display & " Display"
MsgBox .ColorRGB & " Color"
MsgBox .Type & " Type"
MsgBox .Font & " Font"
End With

'return

End Function

There is no way to "receive all parameters in one go as an array". The
Dialog object returned by Application.Dialogs(wdDialogFormatDefineStyleFont)
_is_ the container for all the parameters. You can get or set (if settable)
each parameter by referring to it with the syntax you already have.

In all Word versions from Word 97 onward (that is, the versions that use
VBA), there is a VBA Help topic called "Built-in Dialog Box Argument Lists".
However, all it gives is the names of the arguments, with nothing about
their data types, value limits, or meanings. Often you can guess at these
things by comparing the arguments to the controls in the dialog, but it can
take some time-consuming experiments to get the details.

The article http://www.word.mvps.org/FAQs/MacrosVBA/WordDlgHelp.htm has a
link to download the old WordBasic help file, which has a lot of the missing
type and meaning descriptions. Much of that information is still applicable
to the VBA dialogs. Of course, it doesn't describe anything that was added
to the dialogs after Word 95, and the .ColorRGB argument is one of those.
Also, as noted in the mvps.org article, some dialog parameters don't work.

If you have a question about a particular parameter, you can often find the
answer in the newsgroups by using Google Groups Advanced Search
(http://groups.google.com/advanced_search).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
O

Oliverm

....
In all Word versions from Word 97 onward (that is, the versions that use
VBA), there is a VBA Help topic called "Built-in Dialog Box Argument Lists".
However, all it gives is the names of the arguments, with nothing about
their data types, value limits, or meanings. Often you can guess at these
things by comparing the arguments to the controls in the dialog, but it can
take some time-consuming experiments to get the details.

The articlehttp://www.word.mvps.org/FAQs/MacrosVBA/WordDlgHelp.htmhas a
link to download the old WordBasic help file, which has a lot of the missing ....

If you have a question about a particular parameter, you can often find the
answer in the newsgroups by using Google Groups Advanced Search
(http://groups.google.com/advanced_search).

Thank you, Jay for all your kind explenations. It brought me a step
further.

Oliver
 

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

Similar Threads


Top