From: andreas on
Dear Experts:

I would like to delete ...
the only text box and the only table in the section where the cursor
resides using VBA.
If either no text box or no table is found in the current section, a
msgbox has to say so and the macro is to exit.


Help is much appreciated. Thank you very much in advance for your
professional help.

Regards, Andreas
From: Fumei2 via OfficeKB.com on
Sub DeleteFF_Table()
Dim oTable As Table
Dim oFF As FormField
Dim j As Long

j = Selection.Sections(1).Index

For Each oFF In ActiveDocument.Sections(j).Range.FormFields
oFF.Delete
Next
For Each oTable In ActiveDocument.Sections(j).Range.Tables
oTable.Delete
Next
End Sub

This deletes all formfields and all tables from the Section the cursor is in.

Oh, right you wanted a counter. That makes it a bit longer.

Sub DeleteFF_Table()
Dim oTable As Table
Dim oFF As FormField
Dim j As Long
j = Selection.Sections(1).Index

If ActiveDocument.Sections(j).Range.FormFields.Count > 0 Then
For Each oFF In ActiveDocument.Sections(j).Range.FormFields
oFf.Delete
Next
Else
Msgbox "No formfields in this Section."
End If
If ActiveDocument.Sections(j).Range.Tables.Count > 0 Then
For Each oTable In ActiveDocument.Sections(j).Range.Tables
oTable.Delete
Next
Else
Msgbox "No tables in this Section."
End If
End Sub

Of course you can also combine the two messages if you like, or give just one.
..something like:

"No tables found in this Section. Three formfields deleted."

Or whatever.

Gerry

andreas wrote:
>Dear Experts:
>
>I would like to delete ...
>the only text box and the only table in the section where the cursor
>resides using VBA.
>If either no text box or no table is found in the current section, a
>msgbox has to say so and the macro is to exit.
>
>Help is much appreciated. Thank you very much in advance for your
>professional help.
>
>Regards, Andreas

--
Gerry

Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.aspx/word-programming/201005/1

From: andreas on
On May 20, 8:44 pm, "Fumei2 via OfficeKB.com" <u53619(a)uwe> wrote:
> Sub DeleteFF_Table()
> Dim oTable As Table
> Dim oFF As FormField
> Dim j As Long
>
> j = Selection.Sections(1).Index
>
> For Each oFF In ActiveDocument.Sections(j).Range.FormFields
>    oFF.Delete
> Next
> For Each oTable In ActiveDocument.Sections(j).Range.Tables
>    oTable.Delete
> Next
> End Sub
>
> This deletes all formfields and all tables from the Section the cursor is in.
>
> Oh, right you wanted a counter.  That makes it a bit longer.
>
> Sub DeleteFF_Table()
> Dim oTable As Table
> Dim oFF As FormField
> Dim j As Long
> j = Selection.Sections(1).Index
>
> If ActiveDocument.Sections(j).Range.FormFields.Count > 0 Then
>     For Each oFF In ActiveDocument.Sections(j).Range.FormFields
>        oFf.Delete
>    Next
> Else
>    Msgbox "No formfields in this Section."
> End If
> If ActiveDocument.Sections(j).Range.Tables.Count > 0 Then
>    For Each oTable In ActiveDocument.Sections(j).Range.Tables
>       oTable.Delete
>    Next
> Else
>    Msgbox "No tables in this Section."
> End If
> End Sub
>
> Of course you can also combine the two messages if you like, or give just one.
> .something like:
>
> "No tables found in this Section.  Three formfields deleted."
>
> Or whatever.
>
> Gerry
>
> andreas wrote:
> >Dear Experts:
>
> >I would like to delete ...
> >the only text box and the only table in the section where the cursor
> >resides using VBA.
> >If either no text box or no table is found in the current section, a
> >msgbox has to say so and the macro is to exit.
>
> >Help is much appreciated. Thank you very much in advance for your
> >professional help.
>
> >Regards, Andreas
>
> --
> Gerry
>
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/word-programming/201005/1

Hi Gerry,

sorry for the late reply. I failed to track this question. It is
working as desired. Exactly what I wanted. Thank you very much in
advance. Regards, Andreas