PDA

View Full Version : activate sheet



mike0123m
08-11-2007, 06:11 AM
I have a spreadsheet with four tabs. How can activate the appropriate tab based on the file name of an image in an image control on a userform?

Bob Phillips
08-11-2007, 06:33 AM
I don't think the filename is maintained in the image object.

daniel_d_n_r
08-11-2007, 06:35 AM
you can run code 'onclick' of an image?

mike0123m
08-11-2007, 11:04 AM
I've been trying to use the select case instruction to get this to work but I haven't had any luck with that either.

mike0123m
08-11-2007, 11:21 AM
This is what I have so far but when I click on the ok button, nothing happens:

Sub CommandButton15_click()
Call imagefill
End Sub

Sub imagefill()
Select Case True
Case preview.Picture = LoadPicture("C:/Documents and Settings/Mike/Desktop/Qwik Sheets/Portal Frame/frame1.bmp")
Sheets("df1").Activate

Case preview.Picture = LoadPicture("C:/Documents and Settings/Mike/Desktop/Qwik Sheets/Portal Frame/frame2.bmp")
Sheets("df2").Activate

Case preview.Picture = LoadPicture("C:/Documents and Settings/Mike/Desktop/Qwik Sheets/Portal Frame/frame3.bmp")
Sheets("df3").Activate

Case preview.Picture = LoadPicture("C:/Documents and Settings/Mike/Desktop/Qwik Sheets/Portal Frame/frame4.bmp")
Sheets("df4").Activate

End Select



End Sub

mdmackillop
08-11-2007, 12:18 PM
As XLD says, you can't return the picure name from the image. You could write it though, to a label for example, and recover the name from there
Private Sub UserForm_Initialize()
Dim pic As String
pic = "C:/askim.jpg"
Me.Image1.Picture = LoadPicture("C:/askim.jpg")
Me.Label1.Caption = Split(pic, "/")(UBound(Split(pic, "/")))
End Sub

Private Sub CommandButton1_Click()
MsgBox Me.Label1.Caption
End Sub

Norie
08-11-2007, 12:19 PM
http://www.mrexcel.com/board2/viewtopic.php?t=287323

mike0123m
08-12-2007, 05:56 AM
I'll try that but once the commandbutton is pressed, how do I switch tabs?

mdmackillop
08-12-2007, 05:59 AM
Private Sub CommandButton1_Click()
sheets(left(Me.Label1.Caption,len(Me.Label1.Caption)-4)).activate
End Sub