macr0 buttons how to replace them by text from code

  • Thread starter Michel Posseth [MCP]
  • Start date
M

Michel Posseth [MCP]

Hello



We have some Word documents we need to convert , in a few of these
documents Macro buttons are used as text place holders



We need to be able to replace these macro buttons by text in the document
without knowing on forheand the name of the macro button



so my question :



How can i loop through these macro buttons in a document , and replace them
by text without knowing there names on forehand ( i asume there should be
a sort of collection for them )





Hope someone can help me



Michel
 
G

Greg Maxey

I am not sure I know what an on foreheand is. AFAIK Macrobutton fields
don't have names.

Try something like:

Sub ScratchMacro()
Dim oFld As Word.Field
Dim oFlds As Word.Fields
Set oFlds = ActiveDocument.Fields
For Each oFld In oFlds
If oFld.Type = wdFieldMacroButton Then
oFld.Select
Selection.TypeText "Your Text"
End If
Next
End Sub
 
D

Doug Robbins - Word MVP

beforehand

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

Michel Posseth [MCP]

Indeed .... ( beforehand )

I only saw code examples where it must be known in advance what the macro
button`s tag name is .

As i said i am writing a conversion program ( VS.Net 2008 ) , We loop
through a directory full of word documents and need to replace certain fields

The method we used worked for all "normall" fields in the document but not
for the macro button fields .

As all VBA methods and properties are also availlable with COM interop in VS
( sometimes with a slightly different syntax ) we could get this working
with the code Greg provided


So thank you verry much for your help

Michel Posseth
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top