2 Laszlo:
Here is a link from msdn.
http://msdn.microsoft.com/en-us/library ... 11%29.aspx
I already have code for getting the font specs for the selection or the current ip.
Code:
com_CoInitialize() ; Initialize COM
Word_Open()
Return
#a::
GoSub, CreateFonts
Word_SetFont(DefaultFont)
Word_InsertText("`n`nThanks,`n`n")
Word_SetFont(Font1)
Word_InsertText("Whatever My Name Is`n`n")
Word_SetFont(Font2)
Word_InsertText("email: someone@somewhere.com`n")
Word_InsertText("phone: +50 123 45 21`n")
Word_InsertText("fax: +50 123 45 22`n`n")
Word_SetFont(Font3)
Word_InsertText("Give Me A call or something like that maybe.`n`n")
Word_SetFont(PrevFont)
return
esc::exitapp
CreateFonts:
PrevFont := Word_GetCurrentFont()
DefaultFont := NewFont()
Font1 := NewFont()
Font2 := NewFont()
Font3 := NewFont()
Font4 := NewFont()
Word_FontSetOpt(Font1,"Name","Arial")
Word_FontSetOpt(Font1,"Size",10)
Word_FontSetOpt(Font2,"Name","Times New Roman")
Word_FontSetOpt(Font2,"Size",8)
Word_FontSetOpt(Font3,"Name","Arial")
Word_FontSetOpt(Font3,"Bold",true)
Word_FontSetOpt(Font3,"Underline",true)
Word_FontSetOpt(Font4,"Name","Arial Black")
Word_FontSetOpt(Font4,"Bold",true)
Word_FontSetOpt(Font4,"Underline",true)
/*
; OR
Font1 := "Name=Arial;Size=10;"
Font2 := "Name=Times New Roman;Size=8;"
; note that font options stay in effect until they are changed.
; IE - the size of the following two will be 8, whereas above, they will be the default font size. (my default is 12pt.)
Font3 := "Name=Arial;Bold=1;Underline=1;"
Font4 := "Name=Arial Black;Bold=1;Underline=1;"
*/
return
Word_GetCurrentFont(){
pWord := Word_Attach("A")
pSelection := COM_Invoke(pWord,"Selection")
pFont := COM_Invoke(pSelection,"Font")
StyleList := "Name,Size,Bold,Italic,Underline,AllCaps,DoubleStrikeThrough,Shadow,SmallCaps"
StyleList .= ",StrikeThrough,Subscript,Superscript,Emboss,Position,Spacing"
Loop, Parse, StyleList, `,
{
if !Val := COM_Invoke(pFont,A_LoopField)
Val := 0
sFont .= A_LoopField . "=" . Val . ";"
}
COM_Release(pFont)
COM_Release(pSelection)
COM_Release(pWord)
return sFont
}
Word_GetCurrentFontOpt(sOpt){
pWord := Word_Attach("A")
pSelection := COM_Invoke(pWord,"Selection")
pFont := COM_Invoke(pSelection,"Font")
StyleList := "Name,Size,Bold,Italic,Underline,AllCaps,DoubleStrikeThrough,Shadow,SmallCaps"
StyleList .= ",StrikeThrough,Subscript,Superscript,Emboss,Position,Spacing"
if sOpt in %StyleList%
if !Val := COM_Invoke(pFont,sOpt)
Val := 0
COM_Release(pFont)
COM_Release(pSelection)
COM_Release(pWord)
return Val
}
Word_FontSetOpt(ByRef sFont,sOpt,sVal="¬"){
StyleList := "Name,Size,Bold,Italic,Underline,AllCaps,DoubleStrikeThrough,Shadow,SmallCaps"
StyleList .= ",StrikeThrough,Subscript,Superscript,Emboss,Position,Spacing"
Loop, Parse, StyleList, `,
{
if RegExMatch(sFont,A_LoopField . "=([a-zA-Z0-9\-\s]*)", Prop)
sFont := RegExReplace(sFont,sOpt . "=([a-zA-Z0-9\s]*)",sOpt . "=" . Prop1)
else if sStyle in %StyleList%
{
if (sVal != "¬")
COM_Invoke(pFont,A_LoopField . "=",sVal)
else
COM_Invoke(pFont,A_LoopField . "=",0)
}
}
if RegExMatch(sFont, sOpt . "=([a-zA-Z0-9\s]*)")
sFont := RegExReplace(sFont,sOpt . "=([a-zA-Z0-9\s]*)",sOpt . "=" . sVal)
return sFont
}
Word_FontGetOpt(sFont,sOpt){
RegExMatch(sFont,sOpt . "=([a-zA-Z0-9\s]*)",Opt)
return Opt1
}
NewFont(sDefault="¬"){
static NewFont
if !NewFont {
NewFont := "Name=Times New Roman;Size=12;Bold=0;Italic=0;Underline=0;AllCaps=0;DoubleStrikeThrough=0;"
NewFont .= "Shadow=0;SmallCaps=0;StrikeThrough=0;Subscript=0;Superscript=0;Emboss=0;Position=0;Spacing=0"
}
if (sDefault != "¬")
if (sDefault = "Current")
NewFont := Word_GetCurrentFont()
else
NewFont := sDefault
return NewFont
}
Word_SetFont(sStyle,sVal="¬"){
pWord := Word_Attach("A")
pSelection := COM_Invoke(pWord,"Selection")
pFont := COM_Invoke(pSelection,"Font")
StyleList := "Name,Size,Bold,Italic,Underline,AllCaps,DoubleStrikeThrough,Shadow,SmallCaps"
StyleList .= ",StrikeThrough,Subscript,Superscript,Emboss,Position,Spacing"
Loop, Parse, StyleList, `,
{
if RegExMatch(sStyle,A_LoopField . "=([a-zA-Z0-9\-\s]*)", Prop)
COM_Invoke(pFont,A_LoopField . "=",Prop1)
else if sStyle in %StyleList%
{
if (sVal != "¬")
COM_Invoke(pFont,A_LoopField . "=",sVal)
;MsgBox % A_LoopField . " = " . sVal
else
COM_Invoke(pFont,A_LoopField . "=",0)
}
}
COM_Release(pFont)
COM_Release(pSelection)
COM_Release(pWord)
Return
}
#Include MSOFFICE_COM.ahk
#Include COM.ahk
it probably has a bug or 2....
I had not posted before because I am still not sure if I like the way the user has to set the formatting...Do you have any suggestions? (or anyone else for that matter)