Consulting

Results 1 to 5 of 5

Thread: Align a picture in the center of the screen using VBA

  1. #1
    VBAX Newbie
    Joined
    Jan 2009
    Posts
    3
    Location

    Align a picture in the center of the screen using VBA

    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 ?


    [VBA]Sub SHOW_WAIT()
    ActiveSheet.Shapes("Picture 1").Visible = True
    End Sub[/VBA]

    Thanks in advance

  2. #2
    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
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Newbie
    Joined
    Jan 2009
    Posts
    3
    Location

    Picture Alignment in the center of the screen (SOLVED)

    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.

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,776
    [VBA]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[/VBA]

  5. #5
    VBAX Newbie
    Joined
    Jan 2009
    Posts
    3
    Location

    Smile Picture Alignment in the center of the screen (SOLVED)

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •