PC Review


Reply
Thread Tools Rate Thread

Custom images on a button or other control

 
 
ti@sonic.net Powell
Guest
Posts: n/a
 
      30th Jul 2009
Hi all,

I want to change the images on a button or other object suitable for a
control. I neet to create a three or four state "button" and I think
that a changing icon image is the best way.

I have seen where vba can be used to load an image off of storage...
but that seems foolish given that I will have many buttons... and they
will be constantly/regularly changing.

Is there a way that I can somehow imbed the image into my worksheet
and then reference to that so that the image source remains local to
the worksheet? This will of course make the worksheet far more
portable as opposed to breaking if someone not on my network tries to
use it.

Code snippits appreciated!

Thank you so much.

-Ryder-
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      30th Jul 2009
I'm not sure what you're doing, but you can use pictures (insert|pictures|from
file) directly on the worksheet and assign them each the same macro.

If you name the pictures consistently, you can just hide the ones you don't want
and show the next in the sequence.

For instance, I put 4 pictures in the same location and named them:

PicA_01
PicA_02
PicA_03
PicA_04

And then I assigned them all this macro:

Option Explicit
Sub testme()
Dim WhichOneIsVisible As Long
Dim pCtr As Long
Dim myPict As Picture
Dim myPrefix As String
Dim UnderScorePos As Long

Set myPict = ActiveSheet.Pictures(Application.Caller)
UnderScorePos = InStr(1, myPict.Name, "_", vbTextCompare)

If UnderScorePos = 0 Then
MsgBox "Design error!" & vbLf & "Contact Ryder at xxxxxx"
Exit Sub
End If

myPrefix = Left(myPict.Name, UnderScorePos - 1)
WhichOneIsVisible = Val(Mid(myPict.Name, UnderScorePos + 1))

'your code that does the real work here
'even if it's just a bunch of calls


'hide the old picture
myPict.Visible = False

'determine the next one that should be visible
Set myPict = Nothing
On Error Resume Next
Set myPict = ActiveSheet.Pictures(myPrefix & "_" _
& Format(WhichOneIsVisible + 1, "00"))
On Error GoTo 0

'show the next in the sequence
If myPict Is Nothing Then
'at the last one of the group so show the first
ActiveSheet.Pictures(myPrefix & "_01").Visible = True
Else
myPict.Visible = True
End If

End Sub

"(E-Mail Removed) Powell" wrote:
>
> Hi all,
>
> I want to change the images on a button or other object suitable for a
> control. I neet to create a three or four state "button" and I think
> that a changing icon image is the best way.
>
> I have seen where vba can be used to load an image off of storage...
> but that seems foolish given that I will have many buttons... and they
> will be constantly/regularly changing.
>
> Is there a way that I can somehow imbed the image into my worksheet
> and then reference to that so that the image source remains local to
> the worksheet? This will of course make the worksheet far more
> portable as opposed to breaking if someone not on my network tries to
> use it.
>
> Code snippits appreciated!
>
> Thank you so much.
>
> -Ryder-


--

Dave Peterson
 
Reply With Quote
 
Ryder S
Guest
Posts: n/a
 
      30th Jul 2009

Hi Dave,

Yes, I thought of that... but I have maybe 20 buttons... and I don't
want to have 20x4 buttons... I think I would get carpal tunnel just
setting up 80 buttons for something that should be easy to do.... just
by changing the image on the control... instead of playing visibility
tricks on them.

I noticed that by examining: Me.CommandButton1.Picture I see
some number... perhaps it is a pointer to an image that I can exploit?

I played around with it withoug success.

Any idea what this is and how I might exploit it?

Thanks!

-RS-


On Jul 29, 6:52*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
> I'm not sure what you're doing, but you can use pictures (insert|pictures|from
> file) directly on the worksheet and assign them each the same macro.
>
> If you name the pictures consistently, you can just hide the ones you don't want
> and show the next in the sequence.
>
> For instance, I put 4 pictures in the same location and named them:
>
> PicA_01
> PicA_02
> PicA_03
> PicA_04
>
> And then I assigned them all this macro:
>
> Option Explicit
> Sub testme()
> * * Dim WhichOneIsVisible As Long
> * * Dim pCtr As Long
> * * Dim myPict As Picture
> * * Dim myPrefix As String
> * * Dim UnderScorePos As Long
>
> * * Set myPict = ActiveSheet.Pictures(Application.Caller)
> * * UnderScorePos = InStr(1, myPict.Name, "_", vbTextCompare)
>
> * * If UnderScorePos = 0 Then
> * * * * MsgBox "Design error!" & vbLf & "Contact Ryder at xxxxxx"
> * * * * Exit Sub
> * * End If
>
> * * myPrefix = Left(myPict.Name, UnderScorePos - 1)
> * * WhichOneIsVisible = Val(Mid(myPict.Name, UnderScorePos + 1))
>
> * * 'your code that does the real work here
> * * 'even if it's just a bunch of calls
>
> * * 'hide the old picture
> * * myPict.Visible = False
>
> * * 'determine the next one that should be visible
> * * Set myPict = Nothing
> * * On Error Resume Next
> * * Set myPict = ActiveSheet.Pictures(myPrefix & "_" _
> * * * * * * * * * * *& Format(WhichOneIsVisible + 1, "00"))
> * * On Error GoTo 0
>
> * * 'show the next in the sequence
> * * If myPict Is Nothing Then
> * * * * 'at the last one of the group so show the first
> * * * * ActiveSheet.Pictures(myPrefix & "_01").Visible = True
> * * Else
> * * * * myPict.Visible = True
> * * End If
>
> End Sub
>
>
>
>
>
> "t...@sonic.net Powell" wrote:
>
> > Hi all,

>
> > I want to change the images on a button or other object suitable for a
> > control. *I neet to create a three or four state "button" and I think
> > that a changing icon image is the best way.

>
> > I have seen where vba can be used to load an image off of storage...
> > but that seems foolish given that I will have many buttons... and they
> > will be constantly/regularly changing.

>
> > Is there a way that I can somehow imbed the image into my worksheet
> > and then reference to that so that the image source remains local to
> > the worksheet? *This will of course make the worksheet far more
> > portable as opposed to breaking if someone not on my network tries to
> > use it.

>
> > Code snippits appreciated!

>
> > Thank you so much.

>
> > -Ryder-

>
> --
>
> Dave Peterson- Hide quoted text -
>
> - Show quoted text -


 
Reply With Quote
 
Ryder S
Guest
Posts: n/a
 
      30th Jul 2009

Oh! I did find something that works!

I made 4 additional buttons that have the images on them that I want.
I can then set any OTHER button to those buttons:


Private Sub CommandButton1_Click()
Me.CommandButton3.Picture = PlaceholderButton1.Picture
End Sub

From there, it should be easy to make a 4-way toggle...

-RS-


On Jul 30, 9:46*am, Ryder S <ryderspearm...@gmail.com> wrote:
> Hi Dave,
>
> Yes, I thought of that... but I have maybe 20 buttons... and I don't
> want to have 20x4 buttons... I think I would get carpal tunnel just
> setting up 80 buttons for something that should be easy to do.... just
> by changing the image on the control... instead of playing visibility
> tricks on them.
>
> I noticed that by examining: * * Me.CommandButton1.Picture * I see
> some number... perhaps it is a pointer to an image that I can exploit?
>
> I played around with it withoug success.
>
> Any idea what this is and how I might exploit it?
>
> Thanks!
>
> -RS-
>
> On Jul 29, 6:52*pm, Dave Peterson <peter...@verizonXSPAM.net> wrote:
>
>
>
> > I'm not sure what you're doing, but you can use pictures (insert|pictures|from
> > file) directly on the worksheet and assign them each the same macro.

>
> > If you name the pictures consistently, you can just hide the ones you don't want
> > and show the next in the sequence.

>
> > For instance, I put 4 pictures in the same location and named them:

>
> > PicA_01
> > PicA_02
> > PicA_03
> > PicA_04

>
> > And then I assigned them all this macro:

>
> > Option Explicit
> > Sub testme()
> > * * Dim WhichOneIsVisible As Long
> > * * Dim pCtr As Long
> > * * Dim myPict As Picture
> > * * Dim myPrefix As String
> > * * Dim UnderScorePos As Long

>
> > * * Set myPict = ActiveSheet.Pictures(Application.Caller)
> > * * UnderScorePos = InStr(1, myPict.Name, "_", vbTextCompare)

>
> > * * If UnderScorePos = 0 Then
> > * * * * MsgBox "Design error!" & vbLf & "Contact Ryder at xxxxxx"
> > * * * * Exit Sub
> > * * End If

>
> > * * myPrefix = Left(myPict.Name, UnderScorePos - 1)
> > * * WhichOneIsVisible = Val(Mid(myPict.Name, UnderScorePos + 1))

>
> > * * 'your code that does the real work here
> > * * 'even if it's just a bunch of calls

>
> > * * 'hide the old picture
> > * * myPict.Visible = False

>
> > * * 'determine the next one that should be visible
> > * * Set myPict = Nothing
> > * * On Error Resume Next
> > * * Set myPict = ActiveSheet.Pictures(myPrefix & "_" _
> > * * * * * * * * * * *& Format(WhichOneIsVisible +1, "00"))
> > * * On Error GoTo 0

>
> > * * 'show the next in the sequence
> > * * If myPict Is Nothing Then
> > * * * * 'at the last one of the group so show the first
> > * * * * ActiveSheet.Pictures(myPrefix & "_01").Visible = True
> > * * Else
> > * * * * myPict.Visible = True
> > * * End If

>
> > End Sub

>
> > "t...@sonic.net Powell" wrote:

>
> > > Hi all,

>
> > > I want to change the images on a button or other object suitable for a
> > > control. *I neet to create a three or four state "button" and I think
> > > that a changing icon image is the best way.

>
> > > I have seen where vba can be used to load an image off of storage...
> > > but that seems foolish given that I will have many buttons... and they
> > > will be constantly/regularly changing.

>
> > > Is there a way that I can somehow imbed the image into my worksheet
> > > and then reference to that so that the image source remains local to
> > > the worksheet? *This will of course make the worksheet far more
> > > portable as opposed to breaking if someone not on my network tries to
> > > use it.

>
> > > Code snippits appreciated!

>
> > > Thank you so much.

>
> > > -Ryder-

>
> > --

>
> > Dave Peterson- Hide quoted text -

>
> > - Show quoted text -- Hide quoted text -

>
> - Show quoted text -


 
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
adding custom images to a button on custom toolbar Mousam Microsoft Excel Programming 1 13th Jul 2007 04:28 PM
Custom Button Images =?Utf-8?B?UGZsdWdz?= Microsoft Excel Programming 5 8th Jun 2007 09:16 PM
Custom Button Images and Add-ins =?Utf-8?B?UGxhbiBDaGVja2Vy?= Microsoft Word Document Management 5 6th Apr 2007 07:05 PM
Export custom Macro Button Images RWN Microsoft Excel Setup 1 26th Nov 2006 11:52 AM
Custom button from a Control class doesn't appear as a choice for OK/Cancel button in a Form properties CroDude Microsoft C# .NET 3 28th Jun 2005 06:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:24 PM.