Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
deleting irrelevant sections of a form | Microsoft Word Help | |||
deleting irrelevant sections within a form | Microsoft Word Help | |||
How do I create multiple sections on one for form protection? | Page Layout | |||
Deleting sections of a protected form | Microsoft Word Help | |||
Deleting sections | Microsoft Word Help |