VBA Lightbox? Code and Examples

This is an interesting thread so I thought that I would tinker a bit. Since you are doing a range for the picture, filling a textbox shape is easy enough. This was recently discussed in: http://www.mrexcel.com/forum/showthread.php?t=568219

For the code below, add a CommandButton1 ActiveX control to your sheet. With a selected range, click the button. Click it again gives you an enlarged shape with parts going off the shape and on-top-of the first. Click button again to enlarge and repeat. Click the shapes to delete.

I found the original range values being shown as well so I set a background style which may not suit your needs.
Worksheet code:
Code:
Private Sub CommandButton1_Click()
  LightBoxSelection
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
  LightBoxRange Target, Cancel
End Sub

Module1:
Code:
Sub LightBoxSelection()
  LightBoxRange Selection, False
End Sub

Sub LightBoxRange(Target As Range, Cancel As Boolean)
  Dim pic As Shape
  Dim I As Long
  Target.CopyPicture Appearance:=xlScreen, Format:=xlPicture

  ActiveSheet.Paste

  Set pic = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
  pic.BackgroundStyle = msoBackgroundStylePreset2
  'A bit browner with highlights
  'pic.BackgroundStyle = msoBackgroundStyleMixed + msoBackgroundStylePreset10 + msoBackgroundStylePreset2
  pic.Top = Target.Top

  For I = 10 To 200
      pic.Width = I
      pic.Height = I
  Next I

  pic.OnAction = "DeletePicture"

  Cancel = True

  Application.Goto Target
End Sub

Sub DeletePicture()
    ActiveSheet.Shapes(Application.Caller).Delete
End Sub


Sub t()
  Dim s As Shape
  Set s = ActiveSheet.Shapes("Oval1")
  s.BackgroundStyle
End Sub
 
Last edited:
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Thank you Mr. Hobson. Tmw after work I will give your code a try, and write back. We will see, as hopefully we have solved the debacle.
 
Upvote 0
precicsley. displaying a text box would be the ideal situation. like you said, that is the way it is also done on the internet. do you have any ideas on how to display a text box?

See posts 2 and 3, that code should be adjustable enough to suit your needs. Play with label properties in the properties window until you get the look you want. Use target.text, .value, .formulaR1C1 etc to change what appears in the label. Use target.height, .width to change label.height, .width if necessary
 
Upvote 0
Debacle:
a ~ a great disaster; a complete failure or fiasco

I personally thought we did quite well... oh well, on to the next one...
 
Upvote 0
Thanks.

I think this can be done but it would take a lot of time to put something together that wasn't for a specific purpose/workbook.:)
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,707
Members
452,939
Latest member
WCrawford

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