Thanks, guys.
I am trying to "clean up sloppy coding" to replace Selection objects with
Range objects. A part of my code looped through the shapes, and then
replaced some shapes with other shapes (by opening another Word document and
getting the "new" shapes), using the Selection object. I just want to put
the "retrieved" shape where the deleted shape was, using a Range object.
Now, my question is, how do I edit the shape's (a textbox) font without the
Selection object... (see With oShape.Anchor.Font, below).
I think I may have solved my initial problem by declaring oShape, as
suggested by Jezebel (thanks!). Here's my code:
Sub getShapes()
Dim oShape As Shape, oRng As Range, X As Integer
Dim myBox As String
For X = 1 To ActiveDocument.Shapes.Count
If ActiveDocument.Shapes(X).Name = "myBox" Then
Set oShape = ActiveDocument.Shapes(X)
Set oRng = ActiveDocument.Shapes(X).Anchor
Documents.Open FileName:="c:\myBox.doc"
ActiveDocument.Shapes(1).Select
Selection.Copy
ActiveWindow.Close savechanges:=False
oShape.Delete
oRng.Paste
Set oShape = ActiveDocument.Shapes(X)
With oShape.Anchor.Font
.Name = "Arial"
.Size = 12
.Bold = True
.Color = wdColorAqua
End With
Next
...
theEnd:
End Sub
TIA, again.
st.
Sorry, you've misunderstood what the anchor refers to: the anchor is the
range that the shape is attached to, not the range of the shape's contents.
(Go to Tools > Options, check the 'Object anchors' checkbox, then select the
textbox. You'll see a little anchor in the margin alongside a paragraph --
usually the nearest. That paragraph is the anchor range.) To get to the
content of the textbox, use MyShape.TextFrame.TextRange.
Rather than copying and pasting the textboxes, it might be simpler to copy
the properties --
Dim pDoc as Word.Document
Dim pSource as Word.Shape
Dim pTarget as Word.Shape
'Get the target
Set pTarget = ActiveDocument.Shapes("myBox")
'Get the source
Set pDoc = Documents.Open(FileName:="c:\myBox.doc")
Set pSource = pDoc.Shapes(1)
'Copy from source to target
pSource.Pickup
pTarget.Apply
pTarget.Width = pSource.Width
pTarget.Height = pSource.Height
pTarget.TextFrame.TextRange = pSource.TextFrame.TextRange
etc
'Close the source doc
Set pSource = nothing
pDoc.Close SaveChanges:=Nothing
> Thanks, guys.
>
[quoted text clipped - 68 lines]
>> What kind on manipulation do you want to do to shape object that are
>> normally done to a range object?
zSplash - 19 Apr 2006 18:14 GMT
Amazing, Jezebel! (Compacted the code by more than 75%!!) Your suggestions
(and code) worked great! And, I learned some new concepts and ways to look
at a solution, through you.
Thank you so very much!
st.
> Sorry, you've misunderstood what the anchor refers to: the anchor is the
> range that the shape is attached to, not the range of the shape's contents.
[quoted text clipped - 102 lines]
> >> What kind on manipulation do you want to do to shape object that are
> >> normally done to a range object?
zSplash - 26 Apr 2006 00:22 GMT
Hej, Jezebel,
There are some mailmerge fields in the textbox that I'm copying. How would
I copy those mailmerge fields from pSource to pTarget? (Textfields doesn't
"do it"!)
TIA
st.
> Sorry, you've misunderstood what the anchor refers to: the anchor is the
> range that the shape is attached to, not the range of the shape's contents.
[quoted text clipped - 102 lines]
> >> What kind on manipulation do you want to do to shape object that are
> >> normally done to a range object?
Cindy M -WordMVP- - 28 Apr 2006 13:55 GMT
Hi ZSplash,
> There are some mailmerge fields in the textbox that I'm copying. How would
> I copy those mailmerge fields from pSource to pTarget? (Textfields doesn't
> "do it"!)
Have you tested whether the mergefields actually function in the textboxes?
Generally, I find that a combination to avoid...
Anyway, to pick up the content of an AutoForm that contains text you have to
address its TextFrame.TextRange property. I'd go about it something like
this:
pTarget.TextFrame.TextRange.FormattedText =
pSource.TextFrame.TextRange.FormattedText
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)
zSplash - 15 May 2006 21:58 GMT
Yes, Cindy. It's important that the mergefields remain in the textbox.
I will try your suggestion. Thanks so much for your help!
st.
> Hi ZSplash,
>
[quoted text clipped - 19 lines]
> This reply is posted in the Newsgroup; please post any follow question or
> reply in the newsgroup and not by e-mail :-)