How to center the newly added shape?

Y

Yang Lu

Hello,

I have struggled for 5 hours for this really really simple task, but still
do not know how to do it in Publisher.

All I want to do is to use Shapes.AddTextBox() to add a text to the center
of the view of the active document. Note that it is not the center of page.
It is the center of the view so that user can see it without scrolling.

Basically, all commands from Publisher menu does that. But I cannot figure
out a way to calculate the left and top location of my shape in vba.

Can somebody help me? Thank you so much!
 
E

Ed Bennett

Yang said:
All I want to do is to use Shapes.AddTextBox() to add a text to the center
of the view of the active document. Note that it is not the center of page.
It is the center of the view so that user can see it without scrolling.

I can't bring Mohammed to the mountain, but I can bring the mountain to
Mohammed - create the shape anywhere (e.g. middle of the page; storing a
reference to it in a variable) and then use (Document
object).ActiveView.ScrollShapeIntoView ShapeObject
Basically, all commands from Publisher menu does that.

This is because all commands from the Publisher menus put the shape
where the user drags, and the user can't drag outside the view of the
active document! Since VBA is controlled by the programmer rather than
the user, it puts the shape where the coder specifies with co-ordinates
- not limited to the active view of the active document.
 
Y

Yang Lu

Thank Ed.

ScrollShapeIntoView() is actually the method I am using now. But it zooms in
the shape, which is not what I want. The real code I am using is something
like:

oldZoom = ActiveView.Zoom; // save zoom
doc.ScrollShapeIntoView(shp);
ActiveView.Zoom = oldZoom; // restore zoom

Now, the problem becomes the view flashes because zoom in and out. I also
tried application.ScreenUpdating = false;
but it does not prevent the flashing.

if there is a way we can calculate the scroll position of the view, it would
be perfect and I can put the shape directly in the center of the view.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top