Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
CulinaryDisaster CulinaryDisaster is offline
external usenet poster
 
Posts: 2
Default Macro for deleting multiple sections of a form.

I have a protected form which consists of 13 sections (20 pages in length).
Dependent upon the user's needs, he will only need to fill out 2 or 3
sections. My goal is to write a macro that will unprotect, delete the
unnecessary sections, and save it as a new file. There will be 12 macros
(one for each possible combination)which will reside on a special tool bar in
the document. I've done parts of all of this but have yet to link them
together in a single macro.

My experience in writing macros in VBA is close to non-existent. However, I
do copy, paste and edit with some proficiency. I have copied the
unprotect/protect macro from other posts. I found the following macro to
work when deleting a specific single section:

ActiveDocument.Sections(1).Range.Delete

How do I delete multiple sections - particularly if they are not sequencial
(i.e. Delete sections 2, 3, 5 through 10, 12 and 13)?
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Jean-Guy Marcil[_2_] Jean-Guy Marcil[_2_] is offline
external usenet poster
 
Posts: 373
Default Macro for deleting multiple sections of a form.

"CulinaryDisaster" wrote:

I have a protected form which consists of 13 sections (20 pages in length).
Dependent upon the user's needs, he will only need to fill out 2 or 3
sections. My goal is to write a macro that will unprotect, delete the
unnecessary sections, and save it as a new file. There will be 12 macros
(one for each possible combination)which will reside on a special tool bar in
the document. I've done parts of all of this but have yet to link them
together in a single macro.

My experience in writing macros in VBA is close to non-existent. However, I
do copy, paste and edit with some proficiency. I have copied the
unprotect/protect macro from other posts. I found the following macro to
work when deleting a specific single section:

ActiveDocument.Sections(1).Range.Delete

How do I delete multiple sections - particularly if they are not sequencial
(i.e. Delete sections 2, 3, 5 through 10, 12 and 13)?


ActiveDocument.Sections(1).Range.Delete
deletes the first section in the document.

If you have a contiguous range of sections to delete, you can try something
like this:


Dim rgeDelete As Range

With ActiveDocument
Set rgeDelete = .Range(.Sections(2).Range.Start, .Sections(5).Range.End)
End With
rgeDelete.Delete

This will delete sections 2 to 5.

However, if you delete sections one by one, beware of the reindexing (or
renumbering of the sections).

If you want to delete sections 2 and 4 in a 5-section document, you need to
use:

ActiveDocument.Sections(2).Range.Delete
ActiveDocument.Sections(3).Range.Delete

Because once you delete section 2, what use to be section 4 is now section 3.

One way around that is to delete from the end:

ActiveDocument.Sections(4).Range.Delete
ActiveDocument.Sections(2).Range.Delete

When you delete section 4, section 2 still is section 2...
  #3   Report Post  
Posted to microsoft.public.word.docmanagement
CulinaryDisaster CulinaryDisaster is offline
external usenet poster
 
Posts: 2
Default Macro for deleting multiple sections of a form.

Thank you so much for your help. This worked perfectly. I have amazed and
dazzled my colleagues. They did not think I could pull this off. It would
not have been possible without the information provided in this forum. This
is a real treasure trove.

"Jean-Guy Marcil" wrote:

"CulinaryDisaster" wrote:

I have a protected form which consists of 13 sections (20 pages in length).
Dependent upon the user's needs, he will only need to fill out 2 or 3
sections. My goal is to write a macro that will unprotect, delete the
unnecessary sections, and save it as a new file. There will be 12 macros
(one for each possible combination)which will reside on a special tool bar in
the document. I've done parts of all of this but have yet to link them
together in a single macro.

My experience in writing macros in VBA is close to non-existent. However, I
do copy, paste and edit with some proficiency. I have copied the
unprotect/protect macro from other posts. I found the following macro to
work when deleting a specific single section:

ActiveDocument.Sections(1).Range.Delete

How do I delete multiple sections - particularly if they are not sequencial
(i.e. Delete sections 2, 3, 5 through 10, 12 and 13)?


ActiveDocument.Sections(1).Range.Delete
deletes the first section in the document.

If you have a contiguous range of sections to delete, you can try something
like this:


Dim rgeDelete As Range

With ActiveDocument
Set rgeDelete = .Range(.Sections(2).Range.Start, .Sections(5).Range.End)
End With
rgeDelete.Delete

This will delete sections 2 to 5.

However, if you delete sections one by one, beware of the reindexing (or
renumbering of the sections).

If you want to delete sections 2 and 4 in a 5-section document, you need to
use:

ActiveDocument.Sections(2).Range.Delete
ActiveDocument.Sections(3).Range.Delete

Because once you delete section 2, what use to be section 4 is now section 3.

One way around that is to delete from the end:

ActiveDocument.Sections(4).Range.Delete
ActiveDocument.Sections(2).Range.Delete

When you delete section 4, section 2 still is section 2...

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
deleting irrelevant sections of a form mmh78 Microsoft Word Help 5 May 16th 07 03:26 PM
deleting irrelevant sections within a form mmh78 Microsoft Word Help 0 May 14th 07 06:48 PM
How do I create multiple sections on one for form protection? Audrey Daley Page Layout 1 April 3rd 06 10:25 PM
Deleting sections of a protected form MeganP Microsoft Word Help 1 January 20th 06 02:32 PM
Deleting sections Dr. Therm Microsoft Word Help 3 January 14th 05 06:50 PM


All times are GMT +1. The time now is 07:17 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"