M
mooresk257
Let's see if I can ask this is a way that makes sense:
I have a worksheet with nine image boxes on it named Image1-9. I have
identical code for each image box that handles photo insertion and deletion.
I think I can clean up the code by having the image_click() procedure call a
sub function, rather than duplicate the image handling code nine times for
each imagebox click event.
Question #1:
I can collect the worksheet name as:
Dim SheetID as String
SheetID = ActiveSheet.Name
How do I collect the name (Image1) from the the object that triggers the
click event?
Question #2:
How do I pass these variables to my photo handling code, and construct the
code to reference these variables?
Here's my current photo handling code which I want to make into a sub
function to call with the image click event:
Private Sub Image1_Click()
Dim NewImg As Long
Dim DelImg As Long
NewImg = MsgBox("Insert New Photo?", vbYesNoCancel)
If NewImg = vbYes Then
FileToOpen = Application.GetOpenFilename( _
"All Files (*.jpg),*.jpg, All Files (*.bmp),*.bmp")
If FileToOpen <> False Then
Worksheets("Sheet1").OLEObjects("Image1").Object.Picture _
= LoadPicture(FileToOpen)
With Image1
.BackColor = &H80000005
.BorderStyle = fmBorderStyleNone
End With
End If
ElseIf NewImg = vbNo Then
If Worksheets("Sheet1").OLEObjects("Image1"). _
Object.Picture Is Nothing Then
GoTo Skip
End If
DelImg = MsgBox("Remove Current Photo?", vbYesNo)
If DelImg = vbYes Then
Worksheets("Sheet1").OLEObjects("Image1").Object.Picture =
LoadPicture("")
With Image1
.BackColor = &H8000000F
.BorderStyle = fmBorderStyleSingle
End With
ElseIf DelImg = vbNo Then
End If
ElseIf NewImg = vbCancel Then
End If
Skip:
End Sub
Thanks!
I have a worksheet with nine image boxes on it named Image1-9. I have
identical code for each image box that handles photo insertion and deletion.
I think I can clean up the code by having the image_click() procedure call a
sub function, rather than duplicate the image handling code nine times for
each imagebox click event.
Question #1:
I can collect the worksheet name as:
Dim SheetID as String
SheetID = ActiveSheet.Name
How do I collect the name (Image1) from the the object that triggers the
click event?
Question #2:
How do I pass these variables to my photo handling code, and construct the
code to reference these variables?
Here's my current photo handling code which I want to make into a sub
function to call with the image click event:
Private Sub Image1_Click()
Dim NewImg As Long
Dim DelImg As Long
NewImg = MsgBox("Insert New Photo?", vbYesNoCancel)
If NewImg = vbYes Then
FileToOpen = Application.GetOpenFilename( _
"All Files (*.jpg),*.jpg, All Files (*.bmp),*.bmp")
If FileToOpen <> False Then
Worksheets("Sheet1").OLEObjects("Image1").Object.Picture _
= LoadPicture(FileToOpen)
With Image1
.BackColor = &H80000005
.BorderStyle = fmBorderStyleNone
End With
End If
ElseIf NewImg = vbNo Then
If Worksheets("Sheet1").OLEObjects("Image1"). _
Object.Picture Is Nothing Then
GoTo Skip
End If
DelImg = MsgBox("Remove Current Photo?", vbYesNo)
If DelImg = vbYes Then
Worksheets("Sheet1").OLEObjects("Image1").Object.Picture =
LoadPicture("")
With Image1
.BackColor = &H8000000F
.BorderStyle = fmBorderStyleSingle
End With
ElseIf DelImg = vbNo Then
End If
ElseIf NewImg = vbCancel Then
End If
Skip:
End Sub
Thanks!