Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Get RGB settings

I have a line on a worksheet and its color is set with RGB settings. I
want to select the line and run a macro that will show me the RGB
settings. TIA, James

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Get RGB settings

By line I can't determine if you have a drawing object or cells which
have their pattern set to the pallette.. If it is the cells color then
the VBA code to return it's pallette value is:
-----------------------------
With ActiveCell.Interior
..ColorIndex = NumColor
End With
msgbox (NumColor)
-----------------------------
I am not sure how to extract RGB values from the pallettes own settings
but if you become more clear on the requirement I am sure there is some
solution we can locate.

HTH,
Will


Zone wrote:
I have a line on a worksheet and its color is set with RGB settings. I
want to select the line and run a macro that will show me the RGB
settings. TIA, James


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Get RGB settings

The Line is a drawing object. Thanks, James

wrote:
By line I can't determine if you have a drawing object or cells which
have their pattern set to the pallette.. If it is the cells color then
the VBA code to return it's pallette value is:
-----------------------------
With ActiveCell.Interior
.ColorIndex = NumColor
End With
msgbox (NumColor)
-----------------------------
I am not sure how to extract RGB values from the pallettes own settings
but if you become more clear on the requirement I am sure there is some
solution we can locate.

HTH,
Will


Zone wrote:
I have a line on a worksheet and its color is set with RGB settings. I
want to select the line and run a macro that will show me the RGB
settings. TIA, James


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Get RGB settings

I can extract the pallette value using the code below.. If there is a
requirement to reuse this color elsewhere then you won't need RGB
because all other objects will work with the same pallette..however if
you still need RGB for another purpose let me know.
----------------------------
For Each Shape In ActiveSheet.Shapes
msg = msg & vbCrLf & Shape.Name & " " &
Shape.Line.ForeColor.SchemeColor
Next

MsgBox (msg)
----------------------------


Zone wrote:
The Line is a drawing object. Thanks, James

wrote:
By line I can't determine if you have a drawing object or cells which
have their pattern set to the pallette.. If it is the cells color then
the VBA code to return it's pallette value is:
-----------------------------
With ActiveCell.Interior
.ColorIndex = NumColor
End With
msgbox (NumColor)
-----------------------------
I am not sure how to extract RGB values from the pallettes own settings
but if you become more clear on the requirement I am sure there is some
solution we can locate.

HTH,
Will


Zone wrote:
I have a line on a worksheet and its color is set with RGB settings. I
want to select the line and run a macro that will show me the RGB
settings. TIA, James


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Get RGB settings

Just to add, colour formats in shapes, such as fill, border, line (but not
font) can have a 'fixed-RGB' colour not linked to the palette. With a
'fixed-rgb' colour testing for its Schemecolor will throw an error, which
indeed is how to test for such a format.

Sub test()
Dim ln As Line, cx As Long, clr As Long
For Each ln In ActiveSheet.Lines
With ln.ShapeRange.Line.ForeColor
cx = -1
On Error Resume Next
cx = .SchemeColor 'error if 'fixed-RGB' colour
On Error GoTo 0
clr = .RGB
End With
Debug.Print ln.Name, cx, clr
Next
End Sub

Subtract 7 from the schemecolor to return the equivalent colorindex. But if
cx = 64 the equivalent colorindex is automatic (system black for forecolor),
or -1 in the above example indicates a fixed-rgb colour. There is also a
Backcolor property for the pattern colour (or 2nd effect colour in fill).

Regards,
Peter T

wrote in message
oups.com...
I can extract the pallette value using the code below.. If there is a
requirement to reuse this color elsewhere then you won't need RGB
because all other objects will work with the same pallette..however if
you still need RGB for another purpose let me know.
----------------------------
For Each Shape In ActiveSheet.Shapes
msg = msg & vbCrLf & Shape.Name & " " &
Shape.Line.ForeColor.SchemeColor
Next

MsgBox (msg)
----------------------------


Zone wrote:
The Line is a drawing object. Thanks, James

wrote:
By line I can't determine if you have a drawing object or cells which
have their pattern set to the pallette.. If it is the cells color then
the VBA code to return it's pallette value is:
-----------------------------
With ActiveCell.Interior
.ColorIndex = NumColor
End With
msgbox (NumColor)
-----------------------------
I am not sure how to extract RGB values from the pallettes own

settings
but if you become more clear on the requirement I am sure there is

some
solution we can locate.

HTH,
Will


Zone wrote:
I have a line on a worksheet and its color is set with RGB settings.

I
want to select the line and run a macro that will show me the RGB
settings. TIA, James






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Get RGB settings

Thanks, Peter. Since my drawing object may be set with a scheme color
OR with RGB colors, my next thought was how to detect either. If I
understand your reply correctly, if I try to display the scheme color
for an object set with RGB, I'll get an error, so I could use that
error to bail from the scheme color and go to detecting RGB as Michael
explained.
Regards,
James

Peter T wrote:
Just to add, colour formats in shapes, such as fill, border, line (but not
font) can have a 'fixed-RGB' colour not linked to the palette. With a
'fixed-rgb' colour testing for its Schemecolor will throw an error, which
indeed is how to test for such a format.

Sub test()
Dim ln As Line, cx As Long, clr As Long
For Each ln In ActiveSheet.Lines
With ln.ShapeRange.Line.ForeColor
cx = -1
On Error Resume Next
cx = .SchemeColor 'error if 'fixed-RGB' colour
On Error GoTo 0
clr = .RGB
End With
Debug.Print ln.Name, cx, clr
Next
End Sub

Subtract 7 from the schemecolor to return the equivalent colorindex. But if
cx = 64 the equivalent colorindex is automatic (system black for forecolor),
or -1 in the above example indicates a fixed-rgb colour. There is also a
Backcolor property for the pattern colour (or 2nd effect colour in fill).

Regards,
Peter T

wrote in message
oups.com...
I can extract the pallette value using the code below.. If there is a
requirement to reuse this color elsewhere then you won't need RGB
because all other objects will work with the same pallette..however if
you still need RGB for another purpose let me know.
----------------------------
For Each Shape In ActiveSheet.Shapes
msg = msg & vbCrLf & Shape.Name & " " &
Shape.Line.ForeColor.SchemeColor
Next

MsgBox (msg)
----------------------------


Zone wrote:
The Line is a drawing object. Thanks, James

wrote:
By line I can't determine if you have a drawing object or cells which
have their pattern set to the pallette.. If it is the cells color then
the VBA code to return it's pallette value is:
-----------------------------
With ActiveCell.Interior
.ColorIndex = NumColor
End With
msgbox (NumColor)
-----------------------------
I am not sure how to extract RGB values from the pallettes own

settings
but if you become more clear on the requirement I am sure there is

some
solution we can locate.

HTH,
Will


Zone wrote:
I have a line on a worksheet and its color is set with RGB settings.

I
want to select the line and run a macro that will show me the RGB
settings. TIA, James



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 214
Default Get RGB settings

Hi Zone,
With something like that (by assigning this macro to your line):

Private Type RGB_Wrapper
Red As Byte
Green As Byte
Blue As Byte
Alpha As Byte
End Type

Private Type LNG_Wrapper
Value As Long
End Type

Sub RGB_Settings()
Dim Color As LNG_Wrapper, Colors As RGB_Wrapper
Color.Value = ActiveSheet.Shapes("Line 1").Line.ForeColor
LSet Colors = Color
MsgBox "R: " & Colors.Red & vbLf _
& "G: " & Colors.Green & vbLf _
& "B: " & Colors.Blue
End Sub


"Zone" a écrit dans le message de news:
...
I have a line on a worksheet and its color is set with RGB settings. I
want to select the line and run a macro that will show me the RGB
settings. TIA, James



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 269
Default Get RGB settings

wooooo-hooooo!
Michael, worked like a charm. I've never implemented a user-defined
type before, but it certainly did the trick. I want to get the back
color as well, so I just added that to your code, as below. Any
problem with this? Since the selected object might be a rectangle,
circle or freeform instead of a line, I want to be able to get the fill
RGB as well, so that will be my next effort. I found with a rectangle,
I had to select the actual outline to get the line RGB settings for the
line, which evidently means I'll need to select the fill to get the RGB
settings for the fill. Many thanks. May be posting back.
James

Private Type RGB_Wrapper
Red As Byte
Green As Byte
Blue As Byte
Alpha As Byte
End Type


Private Type LNG_Wrapper
Value As Long
End Type

Sub RGB_Settings()
Dim Color As LNG_Wrapper, Colors As RGB_Wrapper
Dim ColorB As LNG_Wrapper, ColorsB As RGB_Wrapper
Color.Value = Selection.ShapeRange.Line.ForeColor
LSet Colors = Color
ColorB.Value = Selection.ShapeRange.Line.BackColor
LSet ColorsB = ColorB
MsgBox "Line Fore Color" & vbLf & "Red: " & Colors.Red & " " _
& "Green: " & Colors.Green & " " _
& "Blue: " & Colors.Blue & vbLf & vbLf _
& "Line Pattern: " & Selection.ShapeRange.Line.Pattern & vbLf & vbLf
_
& "Line Back Color" & vbLf _
& "Red: " & ColorsB.Red & " " _
& "Green: " & ColorsB.Green & " " _
& "Blue: " & ColorsB.Blue
End Sub

Michel Pierron wrote:
Hi Zone,
With something like that (by assigning this macro to your line):

Private Type RGB_Wrapper
Red As Byte
Green As Byte
Blue As Byte
Alpha As Byte
End Type

Private Type LNG_Wrapper
Value As Long
End Type

Sub RGB_Settings()
Dim Color As LNG_Wrapper, Colors As RGB_Wrapper
Color.Value = ActiveSheet.Shapes("Line 1").Line.ForeColor
LSet Colors = Color
MsgBox "R: " & Colors.Red & vbLf _
& "G: " & Colors.Green & vbLf _
& "B: " & Colors.Blue
End Sub


"Zone" a écrit dans le message de news:
...
I have a line on a worksheet and its color is set with RGB settings. I
want to select the line and run a macro that will show me the RGB
settings. TIA, James


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zero Value Settings Sallie Excel Discussion (Misc queries) 1 April 5th 07 04:28 PM
TAB Settings in Excel Abhi Excel Discussion (Misc queries) 0 October 5th 05 10:33 AM
Settings tjh Excel Discussion (Misc queries) 0 August 9th 05 09:20 PM
settings Bee Excel Worksheet Functions 1 February 22nd 05 06:07 PM
Add to Settings.txt Peter Chatterton[_2_] Excel Programming 1 September 9th 04 05:12 PM


All times are GMT +1. The time now is 10:14 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"