PDA

View Full Version : [SOLVED] How to display a chart on a certain position (e.g. centre of screen).



stranno
08-26-2017, 05:54 AM
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

stranno
08-26-2017, 09:25 AM
This example clarifies what i mean.

Paul_Hossler
08-26-2017, 10:08 AM
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

stranno
08-26-2017, 10:20 AM
Ah, restore dimensions after repositioning the chart. I will check ik out.

stranno
08-26-2017, 11:48 AM
I completely overlooked the z-order part of the code. I will try it again tomorrow.

stranno
08-27-2017, 01:39 AM
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.

Paul_Hossler
08-27-2017, 07:03 AM
Maybe run o.Zorder first then center it might work

Or just call the code twice in the Center sub

stranno
08-27-2017, 08:18 AM
Yes, maybe. i'll try (and error) a few more possibilities. I think I'll find a solution.