Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word automation - can't find text box
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00782504
Message ID:
00783608
Vues:
13
Glad it helped.

>That did it! You don't know how long I've stared at this. I REALLY appreciate your help!
>Kevin
>
>>What about this:
>>For Each aShape In oDoc.Shapes
>> With aShape.TextFrame.TextRange
>>if .hastext &&replace "!lcActNbr!" with "FINALLY!"
>>.text=strtran(.text,"!lcActNbr!","FINALLY!")
>>endif
>>endwith
>>next
>>
>>>Ok, I've determined that my text is in a "shape". From looking through help files and online resources, seems to me that the following should work:
>>>
>>>
>>>For Each aShape In oDoc.Shapes
>>>  With aShape.TextFrame
>>>    IF .HasText <> 0
>>>      .TextRange.Find.Text = "!lcActNbr!"
>>>      .TextRange.Find.Execute
>>>      IF .TextRange.Find.Found
>>>         .TextRange.Text = "FINALLY!"
>>>      ENDIF
>>>    ENDIF
>>>  EndWith
>>>Next
>>>
>>>
>>>It doesn't break (which is a minor miracle!), but the expression never gets found. If anybody has any suggestions or sees anything I'm missing, I would appreciate it!
>>>
>>>Thanks,
>>>Kevin
>>>
>>>>AFAIK, there are two kinds of "Shapes" in Word: Shapes and InlineShapes. From Help:
>>>>*------
>>>>*InlineShape objects are treated like characters and are positioned as characters within a line of text.
>>>>*Shape objects are anchored to a range of text but are free-floating and
>>>>*can be positioned anywhere on the page.
>>>>*You can use the ConvertToInlineShape method and the ConvertToShape method to convert some types of the shapes to inlineshapes.
>>>>*--------
>>>>
>>>>Probably you have "Shapes". Shape types are:
>>>>*msoShapeTypeMixed = -2
>>>>*msoAutoShape=1
>>>>*msoCallout=2
>>>>*msoChart=3
>>>>*msoCommen=4
>>>>*msoFreeform=5
>>>>*msoGroup=6
>>>>*msoEmbeddedOLEObject=7
>>>>*msoFormControl=8
>>>>*msoLine=9
>>>>*msoLinkedOLEObject=10
>>>>*msoLinkedPicture=11
>>>>*msoOLEControlObject=12
>>>>*msoPicture=13
>>>>*msoPlaceholder=14
>>>>*msoTextEffect=15
>>>>*msoMedia =16
>>>>*msoTextBox=17
>>>>
>>>>First try to get the type of this shape. Then you will be able to find a proper method belonging to the shape type to search the text inside.
>>>>
>>>>Something like this:
>>>>for ia=1 to oWord.ActiveDocument.Shapes.Count
>>>> with oWord.ActiveDocument.Shapes(ia)
>>>>?ia,.Type
>>>> endwith
>>>>endfor
>>>>
>>>>
>>>>>Yuri, thanks for the repsonse. After further examination, I have discovered that it isn't actually a text box, but a shape with text within it (TextFrame Object?). I am studying to find a way to manipulate this text, if you have any suggestions, that would be great!
>>>>>
>>>>>Thanks,
>>>>>Kevin
>>>>>
>>>>>>AFAIK text boxes are not visible if active view is set to 'normal'. Try to
>>>>>>set active view to 'page layout'. Then text in textboxes could be also searched for pattern with "FIND". Something like this:
>>>>>>
>>>>>>wdPaneNone=0
>>>>>>wdPageView=3
>>>>>>WITH objWord
>>>>>> If .ActiveWindow.View.SplitSpecial = wdPaneNone
>>>>>> .ActiveWindow.ActivePane.View.Type = wdPageView
>>>>>> Else
>>>>>> .ActiveWindow.View.Type = wdPageView
>>>>>> EndIf
>>>>>>ENDWITH
>>>>>>
>>>>>>>I have a word template that has been driving me crazy. I can replace all the text in the "main story" that I need to, but I have a couple of text boxes on this template that also needs some text replaced. I have tried everything I could think of to get to the text inside these boxes. Everything I've read tells me this should work:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>#DEFINE wdTextFrameStory 5
>>>>>>>NewRange = oDoc.StoryRanges(wdTextFrameStory)
>>>>>>>With NewRange.Find
>>>>>>>  .ClearFormatting
>>>>>>>  .Forward = .T.
>>>>>>>  .Text = "!lcActNbr!"
>>>>>>>  .Execute
>>>>>>>  If .Found
>>>>>>>    NewRange.Text = ALLTR(ltrctr.act_nbr)
>>>>>>>  EndIf
>>>>>>>EndWith
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>No luck. Any help would be greatly appreciated.
>>>>>>>
>>>>>>>Thanks,
>>>>>>>Kevin
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform