PC Review


Reply
Thread Tools Rate Thread

Assign faceid to image on userform

 
 
Ken
Guest
Posts: n/a
 
      11th Nov 2009
How can I assign a FaceID image to an image control in a userform?
Specifically, I want the graph icon associated with FaceId 422
inserted as the picture in a particular Image control on my userform.

Thanks

Ken
 
Reply With Quote
 
 
 
 
Ken
Guest
Posts: n/a
 
      11th Nov 2009
I found my solution here:

http://www.dailydoseofexcel.com/arch...faceid-images/

Ken
 
Reply With Quote
 
minimaster
Guest
Posts: n/a
 
      17th Dec 2009
create an empty userform and put this code into its code module. I
tested it with Excel 2007.

'------------------------------------------------------------------------

Option Explicit

Private Sub UserForm_Initialize()
create500Images ' we create 500 image controls
SetFaces 1 ' we put the faceID's on them
End Sub
Private Sub create500Images()
Dim i As Integer
Dim j As Integer
Dim jten As Integer
Dim n As Integer

Me.Height = 478
Me.Width = 356
For i = 1 To 25
jten = 1
For j = 1 To 20
With Me.Controls.Add("Forms.Image.1", "cmdNewControl")
.Top = (i - 1) * 17 + Fix(n / 100) * 6
.Left = (j - 1) * 17 + jten
.Width = 18
.Height = 18
.BorderColor = vbButtonShadow 'Me.BackColor
.BackColor = Me.BackColor
End With
n = n + 1
If j = 10 Then jten = 6
Next j
Next i
End Sub
Private Sub SetFaces(start As Integer)
Dim i As Integer
Me.Caption = "Excel FaceID's " & CStr(start) & " - " & CStr(start
+ 499)
For i = start To start + 499
With Me.Controls(i - 1)
.Picture = IconBitMap(i)
.ControlTipText = CStr(i)
End With
Next i
End Sub
Function IconBitMap(BfaceID As Integer) As stdole.IPictureDisp

'From Microsoft Office 11.0 Object Library
Dim oBTN As Office.CommandBarButton
'From Microsoft Windows Common Controls 6.0
Dim oIL(0 To 1) As MSComctlLib.ImageList
'From OLE Automation
Dim oIPD As stdole.IPictureDisp
Dim i As Integer

On Error Resume Next
CommandBars("tmpFACEPUMP").Delete
On Error GoTo 0

With CommandBars.Add("tmpFACEPUMP", , , True)
Set oBTN = .Controls.Add(msoControlButton, , , , True)
End With

For i = 0 To 1
Set oIL(i) = New ImageList
With oIL(i)
.ImageHeight = 16
.ImageWidth = 16
.UseMaskColor = True
.MaskColor = IIf(i = 0, vbWhite, vbBlack)
.BackColor = IIf(i = 0, vbButtonFace, vbBlack)
End With
Next

On Error Resume Next

oBTN.FaceId = BfaceID
With oIL(0).ListImages
.Clear
.Add 1, "M", oBTN.Mask
End With
With oIL(1).ListImages
.Clear
.Add 1, "MM", oIL(0).Overlay("M", "M")
.Add 2, "P", oBTN.Picture
End With
Set oIPD = Nothing
Set IconBitMap = oIL(1).Overlay("P", "MM")

End Function
 
Reply With Quote
 
minimaster
Guest
Posts: n/a
 
      18th Dec 2009
Create a userform with 4 commandbuttons on them (w/ default names
CommandButton1, CommandButton2, and so on)
and put the below code into the code module of this new userform.
It basically does the same as J.Walkensbach faceID browser utility,
but this one doesn't suck in Excel 2007 because it is based on a
userform.

'---------------------------------------------------------------------------------------------------------------
Option Explicit
Dim currentFirstButton As Integer

Private Sub UserForm_Initialize()
SetupCmdButtons
Create500Images
SetFacesFast 4, 1, 500 ' we put the faceID's on the images
currentFirstButton = 1
End Sub
Private Sub SetupCmdButtons()
If Controls.count <> 4 Then
MsgBox "There need to be 4 CommandButtons on this form. Not
more and not less. Modify and try again!"
Unload Me
End If

Dim i As Integer
For i = 1 To 4
With Me.Controls(i - 1)
.Top = 1
.Left = i * 18 + 117
.Width = 18
.Height = 18
End With
Next i
SetFacesFast 0, 154, 4
Controls(0).ControlTipText = "Start at 1"
Controls(1).ControlTipText = "back"
Controls(2).ControlTipText = "forward"
Controls(3).ControlTipText = "goto last gallery"
End Sub

Private Sub CommandButton1_Click()
SetFacesFast 4, 1, 500
currentFirstButton = 1
End Sub
Private Sub CommandButton2_Click()
If currentFirstButton > 500 Then
currentFirstButton = currentFirstButton - 500
If currentFirstButton = 8501 Then currentFirstButton = 7501
If currentFirstButton = 5001 Then currentFirstButton = 4001
SetFacesFast 4, currentFirstButton, 500
End If
End Sub
Private Sub CommandButton3_Click()
If currentFirstButton < 10001 Then
currentFirstButton = currentFirstButton + 500
If currentFirstButton = 8001 Then currentFirstButton = 9001
If currentFirstButton = 4501 Then currentFirstButton = 5501
If currentFirstButton = 10001 Then
SetFacesFast 4, currentFirstButton, 100
Else
SetFacesFast 4, currentFirstButton, 500
End If
End If
End Sub
Private Sub CommandButton4_Click()
SetFacesFast 4, 10001, 100
currentFirstButton = 10001
End Sub
Private Sub Create500Images()
Dim i As Integer
Dim j As Integer
Dim jten As Integer
Dim n As Integer

Me.Height = 498
Me.Width = 352
For i = 1 To 25
jten = 1
For j = 1 To 20
With Me.Controls.Add("Forms.Image.1", "cmdNewControl")
.Top = (i - 1) * 17 + Fix(n / 100) * 6 + 20
.Left = (j - 1) * 17 + jten
.Width = 18
.Height = 18
.BorderColor = vbButtonShadow 'Me.BackColor
.BackColor = Me.BackColor
End With
n = n + 1
If j = 10 Then jten = 3
Next j
Next i
End Sub

Private Sub SetFacesFast(FirstCtrlID As Integer, start As Integer,
count As Integer)
Dim i As Integer
Dim j As Integer
'From Microsoft Office 11.0 Object Library
Dim oBTN As Office.CommandBarButton
'From Microsoft Windows Common Controls 6.0
Dim oIL(0 To 1) As MSComctlLib.ImageList

Me.Height = count * 0.91 + 42
Me.Caption = "Excel FaceID's " & CStr(start) & " - " & CStr(start
+ count - 1)
On Error Resume Next
CommandBars("tmpFACEPUMP").Delete
On Error GoTo 0
With CommandBars.Add("tmpFACEPUMP", , , True)
Set oBTN = .Controls.Add(msoControlButton, , , , True)
End With
For i = 0 To 1
Set oIL(i) = New ImageList
With oIL(i)
.ImageHeight = 16
.ImageWidth = 16
.UseMaskColor = True
.MaskColor = IIf(i = 0, vbWhite, vbBlack)
.BackColor = IIf(i = 0, vbButtonFace, vbBlack)
End With
Next
On Error Resume Next

For i = start To start + count - 1
oBTN.FaceId = i
With oIL(0).ListImages
.Clear
.Add 1, "M", oBTN.Mask
End With
With oIL(1).ListImages
.Clear
.Add 1, "MM", oIL(0).Overlay("M", "M")
.Add 2, "P", oBTN.Picture
End With
With Me.Controls(FirstCtrlID + j)
.Picture = oIL(1).Overlay("P", "MM")
.ControlTipText = CStr(i)
End With
j = j + 1
Next i
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
FaceID image in a document Billy B Microsoft Word Document Management 1 9th Mar 2010 11:43 PM
Is it possible to assign faceid to a control on a userform? Edward Microsoft Powerpoint 3 15th Aug 2008 11:47 AM
Assign Keybindings to a Userform =?Utf-8?B?UGF1bFc=?= Microsoft Excel Programming 1 16th May 2007 05:21 PM
Assign shortcut to button on userform MarMo Microsoft Excel Programming 2 24th Oct 2006 02:22 PM
How to assign a DCOUNT function to a userform label Frank Krogh Microsoft Excel Programming 5 18th Mar 2004 10:48 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:47 PM.