Consulting

Results 1 to 8 of 8

Thread: How to display a chart on a certain position (e.g. centre of screen).

  1. #1
    VBAX Tutor
    Joined
    Jun 2005
    Posts
    214
    Location

    How to display a chart on a certain position (e.g. centre of screen).

    I want a shape or chart to be displayed on a certain position in my screen (window) but independent of a specified range.
    The code below doesn't work if certain rows are hidden or filtered.


    Sub Example() 
     CenterShape Me.Shapes("Rectangle 1") 
    End Sub 
    
    Public Sub CenterShape(o As Shape) 
     o.Left = ActiveWindow.VisibleRange(1).Left + (ActiveWindow.VisibleRange.Width / 2 - o.Width / 2) 
     o.Top = ActiveWindow.VisibleRange(1).Top + (ActiveWindow.VisibleRange.Height / 2 - o.Height / 2) 
    End Sub
    Does a chart has a window handle for instance?

    Kind regards,
    Stranno

  2. #2
    VBAX Tutor
    Joined
    Jun 2005
    Posts
    214
    Location
    This example clarifies what i mean.
    Attached Files Attached Files

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    You'll have to store the original .Height and .Width, but maybe this



    Public Sub CenterShape(o As Shape)
    
    o.Left = ActiveWindow.VisibleRange.Left + (ActiveWindow.VisibleRange.Width / 2 - o.Width / 2)
    o.Top = ActiveWindow.VisibleRange.Top + (ActiveWindow.VisibleRange.Height / 2 - o.Height / 2)
    
    o.Width = 450
    o.Height = 250
    
    o.ZOrder (msoBringToFront)
    
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Tutor
    Joined
    Jun 2005
    Posts
    214
    Location
    Ah, restore dimensions after repositioning the chart. I will check ik out.

  5. #5
    VBAX Tutor
    Joined
    Jun 2005
    Posts
    214
    Location
    I completely overlooked the z-order part of the code. I will try it again tomorrow.
    Last edited by stranno; 08-26-2017 at 04:04 PM.

  6. #6
    VBAX Tutor
    Joined
    Jun 2005
    Posts
    214
    Location
    Yes Paul. your suggestion, to bring the chart back to the front was right. Strange enough sometimes you have to click twice to center the chart but that's fine with me. thanks.

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Maybe run o.Zorder first then center it might work

    Or just call the code twice in the Center sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  8. #8
    VBAX Tutor
    Joined
    Jun 2005
    Posts
    214
    Location
    Yes, maybe. i'll try (and error) a few more possibilities. I think I'll find a solution.

Tags for this Thread

Posting Permissions

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