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 / Programming / December 2006

Tip: Looking for answers? Try searching our database.

Finding Macrobutton and delete

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Billy B - 07 Dec 2006 02:11 GMT
I have a table in a Word2000 document. In the table, I have multiple
{macrobutton insertpicture} fields. After inserting the picture, the
placeholder and text appear after the picture, taking up space and displaying
the default text. How can I search the document and delete all instances of
the macrobutton placeholders? I plan on running the procedure in a print
procedure code module.

Thank you very much.
Jay Freedman - 07 Dec 2006 04:40 GMT
Use something like this:

   Dim oRg As Range
   Set oRg = ActiveDocument.Range
   oRg.TextRetrievalMode.IncludeFieldCodes = True
   With oRg.Find
       .ClearFormatting
       .Text = "^d macrobutton"
       .Replacement.Text = ""
       .Forward = True
       .Wrap = wdFindContinue
       .Format = False
       .MatchWildcards = False
       .Execute Replace:=wdReplaceAll
   End With

The .TextRetrievalMode.IncludeFieldCodes lets the search look inside
the field codes even when they're toggled off. The ^d represents the
opening field brace; when that's selected, the entire field is
selected, so replacing with nothing deletes the field.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>I have a table in a Word2000 document. In the table, I have multiple
>{macrobutton insertpicture} fields. After inserting the picture, the
[quoted text clipped - 4 lines]
>
>Thank you very much.
macropod - 07 Dec 2006 05:54 GMT
Or this:

Sub KillMacroButtonFields()
Dim oFld As Field
If ActiveDocument.Fields.Count > 0 Then
   For Each oFld In ActiveDocument.Fields
       If oFld.Type = wdFieldMacroButton Then oFld.Delete
   Next oFld
End If
End Sub

Cheers

Signature

macropod
[MVP - Microsoft Word]

> Use something like this:
>
[quoted text clipped - 32 lines]
> >
> >Thank you very much.
Jay Freedman - 07 Dec 2006 13:06 GMT
It would be interesting to compare these two for speed in a large
document with a few hundred fields.

I'd like to see a contest for the operation in Word that has the most
possible ways of being programmed. :-)

>Or this:
>
[quoted text clipped - 47 lines]
>> >
>> >Thank you very much.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
macropod - 08 Dec 2006 00:02 GMT
Hi Jay,

Interesting, yes, but from a user's perspective, it would probably be even
more efficient to code the macro triggered by the macrobutton field to
delete the calling field as part of the process.

Cheers

Signature

macropod
[MVP - Microsoft Word]

> It would be interesting to compare these two for speed in a large
> document with a few hundred fields.
[quoted text clipped - 59 lines]
> Microsoft Word MVP        FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
Jay Freedman - 08 Dec 2006 01:15 GMT
In point of fact, if the "Typing replaces selection" option is turned
on, the field is deleted automatically, because clicking the
macrobutton to activate it also selects it. Since the OP said his
fields were {MacroButton InsertPicture}, the inserted picture will
replace the field, if that option is set. (But if the InsertPicture
command is being intercepted by a macro of the same name, it could be
doing almost anything.)

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>Hi Jay,
>
[quoted text clipped - 70 lines]
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup
>so all may benefit.
 
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.