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 / Word / Menus and Toolbars / April 2006

Tip: Looking for answers? Try searching our database.

Getting to a really deep nested object

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Maxey - 11 Apr 2006 05:55 GMT
I was working with Nick Turner in a post here recently to unlink only linked Excel worksheets in a document.  Nick has a document where a textbox defines the background of the header and this textbox contains a frame and in the frame is the linked EXCEL field code of interest.

I have got to this point which will unlink a field in a textbox in the header of a plain document, but in the document Nick has it fails on the marked line:

Sub UnlinkExcel()
Dim oStoryRng As Word.Range
Dim oFld As Field
Dim oShp As Shape
Dim i As Long
Dim lngJunk As Long
lngJunk = ActiveDocument.Sections(1).Headers(1).Range.StoryType
For Each oStoryRng In ActiveDocument.StoryRanges
 Do
 For Each oFld In oStoryRng.Fields
   If InStr(oFld.Code.Text, "Excel") > 0 Then oFld.Unlink
 Next oFld
 Select Case oStoryRng.StoryType
   Case 6, 7, 8, 9, 10, 11
     If oStoryRng.ShapeRange.Count > 0 Then
        For Each oShp In oStoryRng.ShapeRange
          If oShp.TextFrame.TextRange.Fields.Count > 0 Then  ********* fails here "The object does not support attached text."
            For i = oShp.TextFrame.TextRange.Fields.Count To 1 Step -1
              If InStr(oShp.TextFrame.TextRange.Fields(i).Code.Text, "Excel") > 0 Then oShp.TextFrame.TextRange.Fields(i).Unlink
            Next i
          End If
        Next oShp
       End If
     Case Else
       'Do Nothing
   End Select
 Set oStoryRng = oStoryRng.NextStoryRange
 Loop Until oStoryRng Is Nothing
Next
End Sub

Can anyone offer insight on how to drill down to the a field in a frame, in a textbox, in a header?  Thanks
Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Cindy M  -WordMVP- - 11 Apr 2006 11:03 GMT
Hi Greg,

> I was working with Nick Turner in a post here recently to unlink only linked Excel worksheets in a document.  Nick has a document where a textbox defines the
background of the header and this textbox contains a frame and in the frame is the
linked EXCEL field code of interest.

A text box cannot contain a frame. So...

But the line you show:
> If oShp.TextFrame.TextRange.Fields.Count > 0 Then  ********* fails here "The object does not support attached text."

I'd check what *TYPE* of shape this is failing on, and only execute it on "valid"
shapes 8shapes that support a TextFrame.TextRange (these would be only
AutoShapes).

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 :-)
Greg Maxey - 11 Apr 2006 11:19 GMT
Cindy,

Thanks, I'll give your idea a try.   I see that I posted accidentally in the
wrong group so will close this thread and reopen in VBA if I need to.
Thanks again.

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

> Hi Greg,
>
[quoted text clipped - 26 lines]
> reply in
> the newsgroup and not by e-mail :-)
Cindy M  -WordMVP- - 11 Apr 2006 15:35 GMT
Hi Greg,

> I see that I posted accidentally in the
> wrong group so will close this thread and reopen in VBA if I need to.

<G> I wondered about that...

   Cindy
 
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.