Metallic Background Colours / Other Colours

thorpyuk

Well-known Member
Joined
Mar 14, 2006
Messages
1,453
Hiya,

Does anyone know if this is possible? The idea came about after wanting to show a 'gold' 'silver' and 'bronze' background colour, but having to plump for yellow, grey and orange looked a little crap :f


Does anyone know if this is possible?

If not, can a workaround be created by using code and a picture or 2?

Thanks guys
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
You can use any valid picture that you wish. Here is a built in custom background designer using Excel's autoshapes. Download the workbook to see how it works. It simply resizes an autoshape to the visible range, takes its picture, and then sets that picture as the worksheets background. The third example shows how to use a group to design a background with a watermark.

Example Download: WorkSheetBackgroundDesigner.zip

<table width="100%" border="1" bgcolor="White" style="filter:progid:DXImageTransform.Microsoft.Gradient(endColorstr='#C0CFE2', startColorstr='#FFFFFF', gradientType='0');"><tr><TD><font size="2" face=Courier New>  <font color="#0000A0">Option</font> <font color="#0000A0">Explicit</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Type</font> PicInformation
     Length <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
     PicType <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
     Handle <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
     NotUsedHere <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Type</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Type</font> GUID
     Data1 <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
     Data2 <font color="#0000A0">As</font> <font color="#0000A0">Integer</font>
     Data3 <font color="#0000A0">As</font> <font color="#0000A0">Integer</font>
     Data4(7) <font color="#0000A0">As</font> <font color="#0000A0">Byte</font>
  <font color="#0000A0">End</font> <font color="#0000A0">Type</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> OleCreatePictureIndirect <font color="#0000A0">Lib</font> "olepro32.dll" (PicDesc <font color="#0000A0">As</font> PicInformation, RefIID <font color="#0000A0">As</font> GUID, <font color="#0000A0">ByVal</font> fPictureOwnsHandle <font color="#0000A0">As</font> Long, IPic <font color="#0000A0">As</font> IPicture) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> CloseClipboard <font color="#0000A0">Lib</font> "user32" () <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> OpenClipboard <font color="#0000A0">Lib</font> "user32" (ByVal hwnd <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> IsClipboardFormatAvailable <font color="#0000A0">Lib</font> "user32" (ByVal wFormat <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>
  <font color="#0000A0">Private</font> <font color="#0000A0">Declare</font> <font color="#0000A0">Function</font> GetClipboardData <font color="#0000A0">Lib</font> "user32" (ByVal wFormat <font color="#0000A0">As</font> Long) <font color="#0000A0">As</font> <font color="#0000A0">Long</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> CF_BITMAP <font color="#0000A0">As</font> <font color="#0000A0">Long</font> = 2
  <font color="#0000A0">Private</font> <font color="#0000A0">Const</font> OLE_PICTYPE_BITMAP = 1

  <font color="#0000A0">Sub</font> Example1()
       Shape2SheetBG Sheet1.Shapes("Rectangle 1"), Sheet2
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>

  <font color="#0000A0">Sub</font> Example2()
       Shape2SheetBG Sheet1.Shapes("Rectangle 2"), Sheet2
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>

  <font color="#0000A0">Sub</font> Example3()
       Shape2SheetBG Sheet1.Shapes("Group 1"), Sheet2
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>

  <font color="#0000A0">Sub</font> Example4()
       Shape2SheetBG Sheet1.Shapes("Rectangle 4"), Sheet2
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>

  <font color="#0000A0">Private</font> <font color="#0000A0">Sub</font> Shape2SheetBG(sh <font color="#0000A0">As</font> Shape, ApplyToWs <font color="#0000A0">As</font> Worksheet)
       <font color="#0000A0">Dim</font> PicPtr <font color="#0000A0">As</font> Long, Pic <font color="#0000A0">As</font> IPictureDisp, IIG <font color="#0000A0">As</font> GUID, PicInfo <font color="#0000A0">As</font> PicInformation
       <font color="#0000A0">Dim</font> OldWidth <font color="#0000A0">As</font> Single, OldHeight <font color="#0000A0">As</font> <font color="#0000A0">Single</font>

       Application.ScreenUpdating = <font color="#0000A0">False</font>
       ApplyToWs.Activate

       OldWidth = sh.Width
       OldHeight = sh.Height

       <font color="#0000A0">With</font> ActiveWindow
           sh.Width = .VisibleRange.Width
           sh.Height = .VisibleRange.Height
       <font color="#0000A0">End</font> <font color="#0000A0">With</font>

       sh.CopyPicture , xlBitmap
       OpenClipboard 0
       <font color="#0000A0">If</font> IsClipboardFormatAvailable(CF_BITMAP) = 0 <font color="#0000A0">Then</font> <font color="#0000A0">Exit</font> <font color="#0000A0">Sub</font>
       PicPtr = GetClipboardData(CF_BITMAP)
       CloseClipboard

       <font color="#0000A0">With</font> IIG
           .Data1 = &H7BF80980
           .Data2 = &HBF32
           .Data3 = &H101A
           .Data4(0) = &H8B
           .Data4(1) = &HBB
           .Data4(3) = &HAA
           .Data4(5) = &H30
           .Data4(6) = &HC
           .Data4(7) = &HAB
       <font color="#0000A0">End</font> <font color="#0000A0">With</font>

       <font color="#0000A0">With</font> PicInfo
         .Length = Len(PicInfo)
         .PicType = OLE_PICTYPE_BITMAP
         .Handle = PicPtr
       <font color="#0000A0">End</font> <font color="#0000A0">With</font>

       OleCreatePictureIndirect PicInfo, IIG, True, Pic
       SavePicture Pic, "C:\Users\Tom\Documents\TempWsBg.bmp"
       ApplyToWs.SetBackgroundPicture "C:\Users\Tom\Documents\TempWsBg.bmp"

       sh.Width = OldWidth
       sh.Height = OldHeight
  <font color="#0000A0">End</font> <font color="#0000A0">Sub</font>
</FONT></td></tr></table><button onclick='document.all("1029200712813621").value=document.all("1029200712813621").value.replace(/<br \/>\s\s/g,"");document.all("1029200712813621").value=document.all("1029200712813621").value.replace(/<br \/>/g,"");window.clipboardData.setData("Text",document.all("1029200712813621").value);'>Copy to Clipboard</BUTTON><textarea style="position:absolute;visibility:hidden" name="1029200712813621" wrap="virtual">
Option Explicit

Private Type PicInformation
Length As Long
PicType As Long
Handle As Long
NotUsedHere As Long
End Type

Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type

Private Declare Function OleCreatePictureIndirect Lib "olepro32.dll" (PicDesc As PicInformation, RefIID As GUID, ByVal fPictureOwnsHandle As Long, IPic As IPicture) As Long
Private Declare Function CloseClipboard Lib "user32" () As Long
Private Declare Function OpenClipboard Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function IsClipboardFormatAvailable Lib "user32" (ByVal wFormat As Long) As Long
Private Declare Function GetClipboardData Lib "user32" (ByVal wFormat As Long) As Long

Private Const CF_BITMAP As Long = 2
Private Const OLE_PICTYPE_BITMAP = 1

Sub Example1()
Shape2SheetBG Sheet1.Shapes("Rectangle 1"), Sheet2
End Sub

Sub Example2()
Shape2SheetBG Sheet1.Shapes("Rectangle 2"), Sheet2
End Sub

Sub Example3()
Shape2SheetBG Sheet1.Shapes("Group 1"), Sheet2
End Sub

Sub Example4()
Shape2SheetBG Sheet1.Shapes("Rectangle 4"), Sheet2
End Sub

Private Sub Shape2SheetBG(sh As Shape, ApplyToWs As Worksheet)
Dim PicPtr As Long, Pic As IPictureDisp, IIG As GUID, PicInfo As PicInformation
Dim OldWidth As Single, OldHeight As Single

Application.ScreenUpdating = False
ApplyToWs.Activate

OldWidth = sh.Width
OldHeight = sh.Height

With ActiveWindow
sh.Width = .VisibleRange.Width
sh.Height = .VisibleRange.Height
End With

sh.CopyPicture , xlBitmap
OpenClipboard 0
If IsClipboardFormatAvailable(CF_BITMAP) = 0 Then Exit Sub
PicPtr = GetClipboardData(CF_BITMAP)
CloseClipboard

With IIG
.Data1 = &H7BF80980
.Data2 = &HBF32
.Data3 = &H101A
.Data4(0) = &H8B
.Data4(1) = &HBB
.Data4(3) = &HAA
.Data4(5) = &H30
.Data4(6) = &HC
.Data4(7) = &HAB
End With

With PicInfo
.Length = Len(PicInfo)
.PicType = OLE_PICTYPE_BITMAP
.Handle = PicPtr
End With

OleCreatePictureIndirect PicInfo, IIG, True, Pic
SavePicture Pic, "C:\Users\Tom\Documents\TempWsBg.bmp"
ApplyToWs.SetBackgroundPicture "C:\Users\Tom\Documents\TempWsBg.bmp"

sh.Width = OldWidth
sh.Height = OldHeight
End Sub</textarea>
 
Upvote 0
Hmmm...

Thanks for your replies guys.. I couldnt download the example right_click, and didn't manage to get the example to work. All it seemed to do was to make my picture blank!

Does anyone else have any ideas?

Are more colours not available in VBA?
 
Upvote 0
Is anyone else having trouble downloading from the link? I just downloaded it without any problem. My server is not local.
 
Upvote 0
Are more colours not available in VBA?

You can define colors with RGB, but Excel (at least pre-XL2007) is limited to the color palette. Any colors defined with RGB will change to what Excel thinks is the closest color in the pallette.

So if you want other colors, you need to change the color pallete.
 
Upvote 0
Well, i'm not too interested in other colours, I just want a nice metallic (silver, gold etc) background behind my cells.....

Sorry right_click, it wasn't your link that was bad, it's my internet server here at work that wont allow me to download .exe files. If it was a .xls file i'd have no problems
 
Upvote 0
Well, i'm not too interested in other colours, I just want a nice metallic (silver, gold etc) background behind my cells....

I think you misunderstand what I'm getting at. If you want to use the standard fills, and want a gold then you have to put that color in the pallette. Now it would just be a gold color, not reflective like metal or anything.
 
Upvote 0

Forum statistics

Threads
1,223,604
Messages
6,173,320
Members
452,510
Latest member
RCan29

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top