If you combine what I posted earlier with what
FanaticGuru posted, you should be able to come up with what you want.
If you want it to turn Black and have no way to go back then:
Code: Select all
F1::
xl := ComObjActive("Excel.Application")
xl.ActiveWorkbook.ActiveSheet.Range("a1:m1").Interior.Color := 0x000000 ; Select Worksheet 1 of the current Excel document. Color is in BGR format meaning 0x0000FF is Red.
xl := ""
Return
If you want to toggle it then:
Code: Select all
F1::
xl := ComObjActive("Excel.Application")
IF (Toggle := !Toggle)
xl.ActiveWorkbook.ActiveSheet.Range("a1:m1").Interior.Color := 0x000000 ; Select Worksheet 1 of the current Excel document. Color is in BGR format meaning 0x0000FF is Red.
Else
xl.ActiveWorkbook.ActiveSheet.Range("a1:m1").Interior.Pattern := 0 ; Select Worksheet 1 of the current Excel document
xl := ""
Return
Hope that helps you understand what you need to do. Check out the Excel COM object model site for more:
https://msdn.microsoft.com/en-us/librar ... 94068.aspx
**Edit
For some reason with my testing the first run of the HotKey will throw an error, but then works fine on subsequent presses. This only happens if excel is opened after the script is running, if the script is started after excel it doesn't appear to happen at all. I found out the reason is because Office products don't register their objects until they lose focus? and you can't connect until its registered. Sure enough if I unfocus Excel then run the HotKey it works without the error, so nothing wrong with the code at all then.
http://stackoverflow.com/questions/1502 ... 0x800401e3
Also since it doesn't appear you are keeping the
xl reference around you could just do:
Code: Select all
F1::ComObjActive("Excel.Application").ActiveWorkbook.ActiveSheet.Range("A1:M1").Interior.Color := 0x000000
OR
Code: Select all
F1::
IF (Toggle := !Toggle)
ComObjActive("Excel.Application").ActiveWorkbook.ActiveSheet.Range("A1:M1").Interior.Color := 0x000000 ; Select Worksheet 1 of the current Excel document. Color is in BGR format meaning 0x0000FF is Red.
Else
ComObjActive("Excel.Application").ActiveWorkbook.ActiveSheet.Range("a1:m1").Interior.Pattern := 0 ; Select Worksheet 1 of the current Excel document
Return