Posted: Light Box Demo
I just posted a workbook that demonstrates how to get a "light box" effect in Excel. You've probably seen Web sites that use this technique when displaying images or pop-ups. Now you can do it in Excel. I tested it with Excel 2003 and 2007.
The workbook has an empty UserForm with a black background. That UserForm is resized to match Excel's window dimensions, and an API function gives it a transparent look. Then, another UserForm (or message box) is displayed on top.
It's pretty simple, and it works well -- but not perfectly. On my system, there's an annoying flicker before the lights go out. If anyone can figure out how to avoid that, please let me know.
Download it here: Light Box Demo.
- Reader Comments -
Following are comments in response to this item.
The most recent comment is at the bottom.
- By JB. Comment posted 23 October, 2009 9:13amOops !
File not found. - By John Walkenbach. Comment posted 23 October, 2009 9:29amFixed. I put in the wrong filename.
- By Mike Alexander. Comment posted 23 October, 2009 10:12amJohn: This is very cool!
I don't think the flicker is all that annoying. And I'm not just saying that to avoid searching for a solution. - By Rick Rothstein. Comment posted 23 October, 2009 12:00pmIt looks like the flicker is coming from the initial placement of UserForm1 before it is moved and expanded. Doing the following seems to remove the flicker. REMOVE these lines from UserForm1's Activate event...
' Adjust UserForm to Excel`s window size
With Me
.Height = Application.Height
.Width = Application.Width
.Left = Application.Left
.Top = Application.Top
End With
and REPLACE the ShowDialog subroutine in Module 1 with this code...
Sub ShowDialog()
With UserForm1
.Height = Application.Height
.Width = Application.Width
.Left = Application.Left
.Top = Application.Top
.Show
End With
End Sub
Doing the above seems to eliminate the flash. - By Rick Rothstein. Comment posted 23 October, 2009 12:02pmI did have one "problem" when I first loaded xllightbox.xls... UserForm1 was not placed directly over Excel window... it was offset down and to the right for a distance that looked equal to the width of a window border. I experimented with some values to move the form into place and finally found some values that worked. BUT, when I closed down the workbook (WITHOUT saving) and then re-opened it (without the adjustment values), the UserForm located itself correctly and has done so since. I have NO idea why the initial running of the code misplaced the UserForm's location nor why it now works correctly (as it should have the first time). I'm just curious... did anyone else see this?
- By John Walkenbach. Comment posted 23 October, 2009 12:23pmThat fix helps a bit, Rick, but I'm still getting a flicker running Excel full screen at 1600 X 1200. If I make Excel's window smaller, it's flicker-free. If I extend Excel's window across two monitors (3200 X 1200), then it's noticeably slower and the flicker is more pronounced. Maybe I just have a slow video card.
- By Rick Rothstein. Comment posted 23 October, 2009 1:14pmHmm, yes, I see the flicker when Excel is at full screen also (I didn't test that initially). And I also see the flicker when the Excel window is stretched across two monitiors. I don't think the problem is a "slow" video card as I have a pretty fast setup in this machine... I have dual NVIDIA GeForce 8800 GTX video cards that are about 2 years old... so I'm guessing the problem is in how Windows manages the display. It is possible that we will just have to live with the flicker for those situations.
- By Nikolas. Comment posted 24 October, 2009 3:10amGood idea, but not working on dual monitors :(
Just dark screen and no dialog boxes. - By Rick Rothstein. Comment posted 24 October, 2009 8:37amTo Nikolas... just as a reference, the code (the original or with my suggested changes to it) works fine on my dual monitor system.
- By John Walkenbach. Comment posted 24 October, 2009 10:41amI don't understand why it wouldn't work on a 2-monitor system. Can you provide any more info, Nikolas?
- By mikii. Comment posted 26 October, 2009 2:39amcool effect, tnx!
- By shaiful. Comment posted 16 November, 2009 9:31amthanks . for good work . but i'm in problem . this is not work at workbook open , with a userform ,please ,help anyone.
- By Volt. Comment posted 21 November, 2009 11:46amTry adding a DoEvents in the UserForm1.Activate module.
' Adjust UserForm to Excel's window size
With Me
.Height = Application.Height
.Width = Application.Width
.Left = Application.Left
.Top = Application.Top
End WithTransparentUserForm Me, 180 'increase to make darker
DoEvents
Select Case Application.Caller
Case "Button 1"
Call ShowPicture
Case "Button 2"
Call ShowMsgBox
End Select - By Ken Warthen. Comment posted 15 February, 2010 8:59amJohn,
What's the "ThunderDFrame" reference in
hWnd = FindWindow("ThunderDFrame", ufcap)
about?
Ken - By Oscar. Comment posted 03 November, 2012 5:53amKen,
'ThunderDFrame' is the classname of userforms made by Excel. - By John Walkenbach. Comment posted 05 November, 2012 7:07pmIt took nearly three years but Ken got an answer.
- By Viggen. Comment posted 03 March, 2013 3:11pmThis XL file crashes my Office 2010, on a Windows XP machine
Spreadsheet Page Blog
Welcome to the Spreadsheet Page Blog. This is where you find the latest news on my books, add-ins, and other Excel-related topics. Comments are welcome.
