Hi, noob here.
Could someone write me a bit of COM
to automatically change the selected text to the Arial font?
Thanks!
COM change font of highlighted text
Re: COM change font of highlighted text
I can do even better than that: just search the forum to find the code that is already written for you.
viewtopic.php?p=379452#p379452
I've never encountered a noob with 206 posts!
viewtopic.php?p=379452#p379452
I've never encountered a noob with 206 posts!
Re: COM change font of highlighted text
@mikeyww
Hi, thanks for the reply.
I cut this part out of the post (and changed it to Arial):
But it doesn't work for selected text; only when nothing is selected.
Hi, thanks for the reply.
I cut this part out of the post (and changed it to Arial):
Code: Select all
^F1::
oWord := ComObjActive("Word.Application")
oWord.Selection.Font.Name := "Arial"
return
Re: COM change font of highlighted text
It works for me as-is on selected text. By the way, you posted it as v1 code, but you posted in the v2 section of the forum. The main lines also work in v2 with the other syntax changed:
Code: Select all
#Requires AutoHotkey v2.0
^F1:: {
oWord := ComObjActive("Word.Application")
oWord.Selection.Font.Name := "Arial"
}
Re: COM change font of highlighted text
Worked here as well.
Re: COM change font of highlighted text
@mikeyww @boiler
I tried changing from selected Times New Roman to Arial and it worked fine.
But I know what the problem is.
See I don't like Chinese-style punctuation, even on Chinese text.
And I found that literally all Chinese punctuation except for double quotation marks, are their own unique symbols.
But the double quotation marks aren't, for some reason.
The Chinese double quotation marks are just a font choice.
And if you select the Chinese text with Chinese quotation marks,
and you manually change it to Arial from Word's drop-down menu, it changes them to regular Arial quotation marks.
But for some reason doing so with this code has no effect.
Any ideas?
Here I made a .gif showing what I'm talking about. (z is the hotkey trigger.)
Keep your eyes on the double quotation mark. See how the menu affects it but the AHK code doesn't?
I tried changing from selected Times New Roman to Arial and it worked fine.
But I know what the problem is.
See I don't like Chinese-style punctuation, even on Chinese text.
And I found that literally all Chinese punctuation except for double quotation marks, are their own unique symbols.
But the double quotation marks aren't, for some reason.
The Chinese double quotation marks are just a font choice.
And if you select the Chinese text with Chinese quotation marks,
and you manually change it to Arial from Word's drop-down menu, it changes them to regular Arial quotation marks.
But for some reason doing so with this code has no effect.
Any ideas?
Here I made a .gif showing what I'm talking about. (z is the hotkey trigger.)
Keep your eyes on the double quotation mark. See how the menu affects it but the AHK code doesn't?
Re: COM change font of highlighted text
There must be something more that Word is doing when selecting a different font from the dropdown than just applying a new font to the entire selection like happens via COM, so the only thing I can suggest is trying to automate the user interface to change the font via the dropdown.
Re: COM change font of highlighted text
@boiler
I tried looking up font-changing code on VBA forums for clues,
and I found this.
Does this mean anything to you?
I tried looking up font-changing code on VBA forums for clues,
and I found this.
Does this mean anything to you?
Re: COM change font of highlighted text
I suppose that could help address the issue, but I don’t have experience with changing the language.