質問

私は、特定のRGB値にセルのフォントの色を設定したい。

私が使用している場合は、

ActiveCell.Color = RGB(255,255,0)

私は黄色得るかが、私は次のように多くのエキゾチックなRGB値を使用する場合:

ActiveCell.Color = RGB(178, 150, 109)

私はちょうど戻ってグレー色を取得します。

どのように私はただのRGB値を使用することはできません来ますか?そして、あなたは回避策を知っていますか?

感謝します。

役に立ちましたか?

解決

Excelが唯一のカラーパレットの色を使用しています。あなたはRGB値を使用してセルを設定すると、それが最も近いですパレットの1を選択します。あなたの色でパレットを更新してから色を選択し、それが動作することができます。

これは、あなたがパレットに現在あるものを見るようになります

 Public Sub checkPalette()
      Dim i As Integer, iRed As Integer, iGreen As Integer, iBlue As Integer
      Dim lcolor As Long
      For i = 1 To 56
        lcolor = ActiveWorkbook.Colors(i)
        iRed = lcolor Mod &H100  'get red component
        lcolor = lcolor \ &H100  'divide
        iGreen = lcolor Mod &H100 'get green component
        lcolor = lcolor \ &H100  'divide
        iBlue = lcolor Mod &H100 'get blue component
        Debug.Print "Palette " & i & ": R=" & iRed & " B=" & iBlue & " G=" & iGreen
      Next i
    End Sub

これは、パレットを設定できます。

Public Sub setPalette(palIdx As Integer, r As Integer, g As Integer, b As Integer)
  ActiveWorkbook.Colors(palIdx) = RGB(r, g, b)
End Sub

他のヒント

クイックヒント:エクセルパレットはほとんど使用されず、通常は他の人々のシートに見える変更せずにカスタム値に設定することができる色の2つの行を持っています。

ここでははるかに少ない不快デフォルトよりも「ソフトトーン」色の合理的なセットを作成するためのコードは次のとおりです。

Public Sub SetPalePalette(Optional wbk As Excel.Workbook) ' This subroutine creates a custom palette of pale tones which you can use for controls, headings and dialogues '

' ** THIS CODE IS IN THE PUBLIC DOMAIN ** ' Nigel Heffernan http://Excellerando.Blogspot.com

' The Excel color palette has two hidden rows which are rarely used: ' Row 1: colors 17 to 24 ' Row 2: colors 25 to 32 - USED BY SetGrayPalette in this workbook '

' Code to capture existing Screen Updating settting and, if necessary, ' temporarily suspend updating while this procedure generates irritating ' flickers onscreen... and restore screen updating on exit if required.

Dim bScreenUpdating As Boolean

bScreenUpdating = Application.ScreenUpdating

If bScreenUpdating = True Then Application.ScreenUpdating = False End If

'If Application.ScreenUpdating <> bScreenUpdating Then ' Application.ScreenUpdating = bScreenUpdating 'End If

If wbk Is Nothing Then Set wbk = ThisWorkbook End If

With wbk

.Colors(17) = &HFFFFD0  ' pale cyan
.Colors(18) = &HD8FFD8  ' pale green.
.Colors(19) = &HD0FFFF  ' pale yellow
.Colors(20) = &HC8E8FF  ' pale orange
.Colors(21) = &HDBDBFF  ' pale pink
.Colors(22) = &HFFE0FF  ' pale magenta
.Colors(23) = &HFFE8E8  ' lavender
.Colors(24) = &HFFF0F0  ' paler lavender

End With

If Application.ScreenUpdating <> bScreenUpdating Then Application.ScreenUpdating = bScreenUpdating End If

End Sub

Public Sub SetGreyPalette() ' This subroutine creates a custom palette of greyshades which you can use for controls, headings and dialogues

' ** THIS CODE IS IN THE PUBLIC DOMAIN ** ' Nigel Heffernan http://Excellerando.Blogspot.com

' The Excel color palette has two hidden rows which are rarely used: ' Row 1: colors 17 to 24 ' - USED BY SetPalePalette in this workbook ' Row 2: colors 25 to 32

' Code to capture existing Screen Updating settting and, if necessary, ' temporarily suspend updating while this procedure generates irritating ' flickers onscreen... remember to restore screen updating on exit!

Dim bScreenUpdating As Boolean

bScreenUpdating = Application.ScreenUpdating

If bScreenUpdating = True Then Application.ScreenUpdating = False End If

'If Application.ScreenUpdating <> bScreenUpdating Then ' Application.ScreenUpdating = bScreenUpdating 'End If

With ThisWorkbook .Colors(25) = &HF0F0F0 .Colors(26) = &HE8E8E8 .Colors(27) = &HE0E0E0 .Colors(28) = &HD8D8D8 .Colors(29) = &HD0D0D0 .Colors(30) = &HC8C8C8 ' &HC0C0C0 ' Skipped &HC0C0C0 - this is the regular 25% grey in the main palette .Colors(31) = &HB8B8B8 ' Note that the gaps are getting wider: the human eye is more sensitive .Colors(32) = &HA8A8A8 ' to changes in light greys, so this will be perceived as a linear scale End With

'The right-hand column of the Excel default palette specifies the following greys:

' Colors(56) = &H333333 ' Colors(16) = &H808080 ' Colors(48) = &H969696 ' Colors(15) = &HC0C0C0 ' the default '25% grey'

' This should be modified to improve the color 'gap' and make the colours easily-distinguishable:

With ThisWorkbook .Colors(56) = &H505050 .Colors(16) = &H707070 .Colors(48) = &H989898 ' .Colors(15) = &HC0C0C0 End With

If Application.ScreenUpdating <> bScreenUpdating Then Application.ScreenUpdating = bScreenUpdating End If

End Sub

あなたは「CaptureColors」と各ワークブックのOpen(のための「ReinstateColors」関数)とBeforeClose()イベントを書き込むことを選択することがあります...あるいは各ワークシートのためにアクティブにし、イベントを無効にします。

私は、32二つのステップで「ホット」な赤に「コールド」青からあなたの進行を与え、3-Dグラフの「熱」色のグラデーションを作成するコードのどこかに転がっています。これは、あなたが思うかもしれないよりも硬い:強度の対数スケール上で実行され、「強い」色として赤、緑、青のための非線形重み付けを有する人間の視覚系(により「等間隔」として知覚される色のグラデーション)の構築に時間がかかる - あなたはあなたが指定した順序で、指定した色を使用してにMSチャートを強制するために、VBAを使用する必要があります。

Sub color()

bj = CStr(Hex(ActiveCell.Interior.Color))
If Len(bj) < 6 Then
    Do Until Len(bj) = 6
        bj = "0" & bj
    Loop
End If

R = CLng("&H" & Right(bj, 2))
bj = Left(bj, Len(bj) - 2)
G = CLng("&H" & Right(bj, 2))
bj = Left(bj, Len(bj) - 2)
B = CLng("&H" & bj)

End Sub

と同様の回答やコメントありがとうございます。

私のクライアントは、カラーパレットを改ざんExcelにインストールされている他のプラグインを持っていたので、

それは本当に私に大きなトラブルを与えます。

私は、特定のColorIndex私の要素をasigningパレット内のいくつかの色を交換することになったが、少年は、それはかなりありません。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top