PDA

View Full Version : Align a picture in the center of the screen using VBA



SprimaX
01-19-2009, 03:29 AM
Hi All,

I use Excel 2003. I have inserted a picture from Insert Menu, Picture, From File into a sheet. Is it possible to align the picture/shape in the center of the screen every time I run the this code below, is it possible to use StartUpPosition, how ?


Sub SHOW_WAIT()
ActiveSheet.Shapes("Picture 1").Visible = True
End Sub

Thanks in advance

Jan Karel Pieterse
01-19-2009, 04:47 AM
I'd put the pic on a userform and show that, userforms show centered by default. If you show the form using:

Userform1.Show vbModeLess

then your code continues to run after that line. Make sure you unload the form too:

Unload Userform1

SprimaX
01-19-2009, 05:27 PM
Mr. Jan Karel,

Thanks for your response and kind attention, maybe it will much better if I use an UserForm as your suggestion.

Thanks a lot.

mikerickson
01-19-2009, 05:45 PM
Sub test()
Dim myPicture As Shape

Set myPicture = ActiveSheet.Shapes("Picture 1")

With ActiveWindow.VisibleRange
myPicture.Top = .Top + .Height / 2 - myPicture.Height / 2
myPicture.Left = .Left + .Width / 2 - myPicture.Width / 2
End With
myPicture.Visible = True
End Sub

SprimaX
01-20-2009, 03:20 AM
Dear Mikerickson,

It's a great code. It worked fine ! Just like I want. It is visible right in the center of the screen or active window.

Thank you, thank you very very very much.