![]() |
#1
|
|||
|
|||
![]()
I've been assigned to design some Word macros to clean up exported requirements documents from Telelogic DOORS. Among other tasks, the current cover page is being exported as an embedded Word document. I need to do two things with it. First, I need to center the embedded object on the page (currently, it's aligned with the left side in the center of the document). Second, I need to go into the embedded object and find a piece of text. I can do the latter once I've opened the OLE object, but I haven't figured out how to do that programmatically yet. My usual method for figuring out how to do things in Word macros is to record a macro and then look at the code, but double-clicking into an object seems to be disabled when recording the macro.
I found an example of opening embedded objects at http://thedailyreviewer.com/windowsa...g-vba-10672616 but that only seems to find the images in my document. ![]() |
#2
|
|||
|
|||
![]()
Ah, figured it out. The object was embedded as a Shape. I discovered this by first realizing that there was a Context Menu item to open the embedded document whereupon I recorded a macro to access it. For the sake of reference, the macro code I got for finding it, opening it, finding a piece of text, copying what followed it, closing the document, and pasting said text into the header is the following:
Code:
If ActiveDocument.Shapes.Count > 0 Then ActiveDocument.Shapes(1).Select Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter With Selection.ParagraphFormat .LeftIndent = InchesToPoints(0#) .FirstLineIndent = InchesToPoints(0#) End With Selection.ShapeRange(1).OLEFormat.DoVerb VerbIndex:=1 Selection.Find.ClearFormatting With Selection.Find .Text = "Document ID" .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.MoveDown Unit:=wdLine, Count:=1 Selection.HomeKey Unit:=wdLine Selection.EndKey Unit:=wdLine, Extend:=wdExtend Selection.Copy Selection.EscapeKey ActiveDocument.Close WordBasic.ViewFooterOnly Selection.TypeText Text:="Document " ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument Else MsgBox ("Failed to find cover page") End If Last edited by DugganSC; 08-29-2011 at 01:42 PM. Reason: Fixing a zero-index issue |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Atlas | Word | 1 | 06-20-2011 04:37 PM |
![]() |
spheon | Word | 1 | 06-07-2011 04:11 PM |
Embedded in invitation? | admin99 | Outlook | 0 | 08-28-2010 05:34 PM |
Problem: object library invalid or contains references to object definitions | aligahk06 | Office | 0 | 08-19-2010 12:29 PM |
Could not load this object as this object is not present in your computer | k.gaurav | Office | 0 | 08-17-2009 09:57 PM |