I'm using the following code to remove some text form fields plus a logo i
have at the top of my template. ub RemoveHeader()
ActiveDocument.FormFields("Text12").Delete
ActiveDocument.FormFields("Text13").Delete
ActiveDocument.FormFields("Text14").Delete
ActiveDocument.FormFields("Text15").Delete
ActiveDocument.FormFields("Text16").Delete
ActiveDocument.FormFields("Text17").Delete
ActiveDocument.FormFields("Text18").Delete
ActiveDocument.Shapes(1).Delete

I would like to modify the code so that I can delete two words located at
the top of the document. The word "Telephone" and the word "Facsimile." I
have tried using the following, however, it does not work:
Selection.Find.Text = ("Telephone")
Selection.Delete

Can someone tell me what I'm doing wrong?

thanks,

RE: Remove Text by Wraithchilde

Wraithchilde
Mon Feb 05 10:20:01 CST 2007

You need to execute the find before you delete, like so:
Selection.Find.Text = ("Telephone")
Selection.Find.Execute
Selection.Delete


RE: Remove Text by EB

EB
Mon Feb 05 10:42:00 CST 2007

The code below does not work. All the Text form fields are removed except
for the word Telephone. I added your code as follows:

Sub RemoveHeader()
ActiveDocument.FormFields("Text12").Delete
ActiveDocument.FormFields("Text13").Delete
ActiveDocument.FormFields("Text14").Delete
ActiveDocument.FormFields("Text15").Delete
ActiveDocument.FormFields("Text16").Delete
ActiveDocument.FormFields("Text17").Delete
ActiveDocument.FormFields("Text18").Delete
ActiveDocument.Shapes(2).Delete
Selection.Find.Text = ("telephone")
Selection.Find.Execute
Selection.Delete
End Sub

I'm new to macros, so I dont understand what I'm doing wrong.

"Wraithchilde" wrote:

> You need to execute the find before you delete, like so:
> Selection.Find.Text = ("Telephone")
> Selection.Find.Execute
> Selection.Delete
>

Re: Remove Text by EB

EB
Mon Feb 05 11:00:00 CST 2007

Edward,

I'm trying to figure out what is the best way for me to proceed with this.
instead of deleting all of the text form fields, the logo, and the words
"Telephone and Facimile" is there a way I can set all that information so
that it does not print or so that it's hidden? my code now looks like this:

Sub RemoveHeader()

Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = ("Telephone")
.Execute
If .Found Then Selection.Delete
End With

With Selection.Find
.Text = ("Facsimile")
.Execute
If .Found Then Selection.Delete
End With

ActiveDocument.FormFields("Text12").Delete
ActiveDocument.FormFields("Text13").Delete
ActiveDocument.FormFields("Text14").Delete
ActiveDocument.FormFields("Text15").Delete
ActiveDocument.FormFields("Text16").Delete
ActiveDocument.FormFields("Text17").Delete
ActiveDocument.FormFields("Text18").Delete
ActiveDocument.Shapes(2).Delete

End Sub

Sorry for all the questions, but I'm learning as I go and I'm trying to
figure out what is the best way to do this.

Thanks,


"Edward Thrashcort" wrote:

> You have to execute a find
>
> Selection.HomeKey Unit:=wdStory
> With Selection.Find
> .Text = ("Telephone")
> .Execute
> If .Found Then Selection.Delete
> End With
>
> Eddie
>

Re: Remove Text by EB

EB
Mon Feb 05 12:51:01 CST 2007

Once again thanks Eddie,

One more question. is there a way to anchor the cursor when running a
macro? After all the formfields, logo, and the two words are deleted the
cursor jumps to where the word "Telephone" use to be. Is there away to keep
anchor below the Continuous Section break?



"Edward Thrashcort" wrote:

> Couldn't you just set the default value of all fields to nothing?
>
> Dim ThisField As FormField
>
> With ActiveDocument.Range
>
> For i = 1 To .FormFields.Count
> Application.StatusBar = "Initialising Formfield " & Str(i)
> Set ThisDocField = .FormFields(i)
> Select Case ThisDocField.Type
> Case wdFieldFormCheckBox: ThisDocField.CheckBox.Default = False
> Case wdFieldFormTextInput: ThisDocField.TextInput.Default = ""
> End Select
> Next
>
> End With
>
> Use the online help to understand the syntax
>
> Eddie
>

Re: Remove Text by lf

lf
Mon Feb 05 16:14:00 CST 2007

In addition to the built-in VBA help (which is really helpful), you will find
a lot of useful macro/VBA information on the Word MVP Site:
http://word.mvps.org/FAQs/MacrosVBA/index.htm

Most often, the same problem can be solved in many different ways using VBA.
Once you get more familiar with VBA, you will find out how you can optimize
your code.

A tip related to your current code:
Instead of repeating the same code line for each FormField you are deleting,
you could use this code:

Dim n As Long
For n = 12 To 18
ActiveDocument.FormFields("Text" & n).Delete
Next n

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"EB" wrote:

> Once again thanks Eddie,
>
> One more question. is there a way to anchor the cursor when running a
> macro? After all the formfields, logo, and the two words are deleted the
> cursor jumps to where the word "Telephone" use to be. Is there away to keep
> anchor below the Continuous Section break?
>
>
>
> "Edward Thrashcort" wrote:
>
> > Couldn't you just set the default value of all fields to nothing?
> >
> > Dim ThisField As FormField
> >
> > With ActiveDocument.Range
> >
> > For i = 1 To .FormFields.Count
> > Application.StatusBar = "Initialising Formfield " & Str(i)
> > Set ThisDocField = .FormFields(i)
> > Select Case ThisDocField.Type
> > Case wdFieldFormCheckBox: ThisDocField.CheckBox.Default = False
> > Case wdFieldFormTextInput: ThisDocField.TextInput.Default = ""
> > End Select
> > Next
> >
> > End With
> >
> > Use the online help to understand the syntax
> >
> > Eddie
> >