Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Publisher / Programming / May 2007

Tip: Looking for answers? Try searching our database.

Referencing Pasted Shapes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cory - 03 May 2007 19:24 GMT
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
Ed Bennett - 04 May 2007 19:21 GMT
> 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

Signature

Ed Bennett - MVP Microsoft Publisher
http://ed.mvps.org

Cory - 07 May 2007 18:51 GMT
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>  

> 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,
[quoted text clipped - 14 lines]
>      Set PastedRange = ActiveDocument.Pages(1).Master.Shapes.Paste
>      PastedRange(1).Top = SoAndSo
Cory - 08 May 2007 12:18 GMT
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

> 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
[quoted text clipped - 18 lines]
>
> Cory
Ed Bennett - 08 May 2007 22:59 GMT
> 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.

Signature

Ed Bennett - MVP Microsoft Publisher
http://ed.mvps.org

Cory - 10 May 2007 13:24 GMT
Alrighty.  Will try that.  Thanks again.

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
[quoted text clipped - 4 lines]
> Immediately after pasting, the "Selection" object would return the
> freshly-pasted ShapeRange.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.