Jump to content

set Excel tab color from variable (SOLVED)


Recommended Posts

Hopefully someone familiar with Excel COM in AutoIt will say "Oh, that's easy, you just..."

Or if someone knows how to set the tab color with the Excel UDF, either way.

specifying the hex directly works...

$oExcelDoc.WorkSheets($Driver).Tab.Color=0x00FF00

declaring the variable directly works...

$Acolor=0x00FF00
$oExcelDoc.WorkSheets($Driver).Tab.Color=$Acolor

BUT... if my variable is set by output from functions or read from ini file (which is what i am trying to do) it doesn't apply the color...

$Acolor=IniRead ( "Colors.ini", "A", "Color", "" )
$oExcelDoc.WorkSheets($Driver).Tab.Color=$Acolor

 

I have quadruple checked that the ini is being read correctly and googled til my eyes popped out and have now gone mad.

Edited by alienclone
SOLVED
If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

Looks like it's because you're getting "0x00FF00", a string, from the file instead of 0x00FF00, a hex value. You're going to have to convert the data type.

From IniRead():

Quote

Return Value

Success: the requested key value as a string.
Failure: the default string if requested key not found.

Try

#include <String.au3>
$Acolor=IniRead ( "Colors.ini", "A", "Color", "" )
$Acolor=_StringToHex($Acolor)
$oExcelDoc.WorkSheets($Driver).Tab.Color=$Acolor

 

Edited by rcmaehl

My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.

My Projects

WhyNotWin11
Cisco FinesseGithubIRC UDFWindowEx UDF

 

Link to comment
Share on other sites

54 minutes ago, rcmaehl said:

Looks like it's because you're getting "0x00FF00", a string, from the file instead of 0x00FF00, a hex value. You're going to have to convert the data type.

From IniRead():

Try

#include <String.au3>
$Acolor=IniRead ( "Colors.ini", "A", "Color", "" )
$Acolor=_StringToHex($Acolor)
$oExcelDoc.WorkSheets($Driver).Tab.Color=$Acolor

 

Oh my goodness, that didn't even occur to me. Of course Excel doesn't know what color 'some random string of letters and numbers' is supposed to be.

It's bed time right now but when I get up I will figure out how to use _HextoString() and _StringtoHex() to convert and report back on whether or not this is the problem, sounds like it is though.

thank you rcmaehl, your script suggestion seems to be converting to the hex value of the string, I may have to play around with hextostring before storing the value, then using stringtohex to bring it back.

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

YAY!  After much confusion I realized I still don't understand binary/hex/dec.

BUT... thanks to rcmaehl pointing me in the right direction, i have solved the problem with...

$Acolor=IniRead ( "Colors.ini", "A", "Color", "" )
$Acolor=Execute($Acolor)
$oExcelDoc.WorkSheets($Driver).Tab.Color=$Acolor

 

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

<rant> having to convert a color MULTIPLE times in one script because I need to trade hexadecimal colors between a program that uses BGR, and one that uses RGB </rant>

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

21 hours ago, AutoBert said:
Func RGB2BGR($iColor)
    Local $sH = Hex($iColor,6)
    Return '0x' & StringRight($sH, 2) & StringMid($sH,3,2) & StringLeft($sH, 2)
EndFunc  ;==>RGB2BGR

i think the BGR2RGB func should be no problem for you

converting was not a problem, i was just complaining about different programs using different color formats.

If @error Then
    MsgBox(262192, "", @ComputerName & " slaps " & @UserName & " around a bit with a large trout!")
EndIf

"Yeah yeah yeah patience, how long will that take?"  -Ed Gruberman

REAL search results  |  SciTE4AutoIt3 Editor Full Version

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...