• Intro to AutoHotkey HotStrings with AutoHotkey Intermediate AutoHotkey GUIs are Easy with AutoHotkey Intro to DOS & AutoHotkey

Set Excel Font type and format with AutoHotkey

AutoHotkey Merchandise-White Stress ballAutomatically Set Excel Font type, size, emphasis with AutoHotkeySet Excel Font

Excel files are a go-to standard form many business people.  Often people will export a file from their “tool” and then spend time making it “pretty” by adjusting font size, type, cell color, formatting, etc.  When I do this, I automate the re-doing of applying formatting over and over which greatly streamlines the process and makes things more consistent.

Tutorial how to use the below AutoHotkey functions

The following AutoHotkey functions are demonstrated in the below above video.  They make it a breeze to update settings in a given Excel range.

AutoHotkey Bottle 2AutoHotkey functions to Set Excel Font type, Size and format

XL_Handle(XL,1) ;get handle to current Excel file
;~ XL_Format_Font(XL,RG:="A1:B1",Font:="Book Antiqua",Size:=20) ;Arial, Arial Narrow, Calibri,Book Antiqua
XL_Format_Format(XL,RG:="A1:B1",Bold:=0,Italic:=0,Underline:=1) ;Underline 1 thru 4

;***********************set size, type, ********************************.

;***********************bold, normal, italic, Underline********************************.
PXL.Application.ActiveSheet.Range(RG).Font.Bold:= bold


Excel Handles

XL_Handle(ByRef PXL,Sel){
ControlGet, hwnd, hwnd, , Excel71, ahk_class XLMAIN ;identify the hwnd for Excel
IfEqual,Sel,1, Return, PXL:= ObjectFromWindow(hwnd,-16).application ;Handle to Excel Application
IfEqual,Sel,2, Return, PXL:= ObjectFromWindow(hwnd,-16).parent ;Handlle to active Workbook
IfEqual,Sel,3, Return, PXL:= ObjectFromWindow(hwnd,-16).activesheet ;Handle to Active Worksheet
;***********adapted from ACC.ahk*******************
ObjectFromWindow(hWnd, idObject = -4){
(if Not h)?h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
 If DllCall("oleacc\AccessibleObjectFromWindow","Ptr",hWnd,"UInt",idObject&=0xFFFFFFFF,"Ptr",-VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
 Return ComObjEnwrap(9,pacc,1)


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Intro to AutoHotkey HotStrings with AutoHotkey Intermediate AutoHotkey GUIs are Easy with AutoHotkey Intro to DOS & AutoHotkey