Referencing Pasted Shapes

C

Cory

I am using VBA code to paste a copied shape to the Master page and then
following on to manipulate the shape (.Top, .Left, etc.). When I refer to
the recently pasted shape (i.e.
ActiveDocument.Pages(1).Master.Shapes(ActiveDocument.Pages(1).Master.Shapes.Count)
which should select the pasted shape since it is the "top" shape) it does
not always select the correct shape.

When running with Breakpoints, and stepping through the code, it works as
intended. WHen running without breaks, it screws up royally. Is there some
other way to refer to that shape? I have tried the following:

With ActiveDocument.Pages(1).Master.Shapes.Paste
.Top = SoAndSo
End With (did not work; Object Required)

Set PastedShape = ActiveDocument.Pages(1).Master.Shapes.Paste

PastedShape.Top = SoAndSo (also did not work, but forget error message)

Any help would be appreciated. Using Publisher 2002.

Cory
 
E

Ed Bennett

Cory said:
When running with Breakpoints, and stepping through the code, it works as
intended. WHen running without breaks, it screws up royally. Is there some
other way to refer to that shape? I have tried the following:

That is *such* an annoying problem (I've run into it - or a similar
issue - myself in other contexts - program runs fine in the debugger,
but try to compile it for your client in Release mode and suddenly it
stops working). I opened a dialogue with Microsoft about it, but never
got a definitive answer on the matter.
Set PastedShape = ActiveDocument.Pages(1).Master.Shapes.Paste

PastedShape.Top = SoAndSo (also did not work, but forget error message)

I don't have access to the Publisher 2002 object model at the moment,
but IIRC it behaved the same in this regard as 2003 and 2007 do - the
..Paste method returns a ShapeRange rather than a Shape. That's why you
can't set the .Top property with your "With" block - .Top for a
ShapeRange is read-only. And I'd wager that the error you're getting
when you Set PastedShape is either the same error or a Type Mismatch.

Try:

Dim PastedRange As ShapeRange
Set PastedRange = ActiveDocument.Pages(1).Master.Shapes.Paste
PastedRange(1).Top = SoAndSo
 
C

Cory

Outstanding!!@! I will have to go try that.

Previously I have had to do the .paste then something like

With ActiveDocument.Pages(1).Shapes(ActiveDocument.Pages(1).Shapes.Count)
.Top = X
.Left = y
.Name = z
End With

..Count will give the current count of shapes which should equal the index of
the newly pasted shape to refer to. <Sigh>
 
C

Cory

It is return "Object or With block defined variable not set." But I set the
object variable in the line immediately before the with block. Is there a
way to access the shape range after pausing the execution with a breakpoint?
I tried using the immeditate window to try and access it and get more
information (like if it was actually there) and I could not seem to.

Any thoughts?

Cory
 
E

Ed Bennett

Cory said:
It is return "Object or With block defined variable not set." But I set the
object variable in the line immediately before the with block. Is there a
way to access the shape range after pausing the execution with a breakpoint?
I tried using the immeditate window to try and access it and get more
information (like if it was actually there) and I could not seem to.

Immediately after pasting, the "Selection" object would return the
freshly-pasted ShapeRange.
 

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