Sarahmueller
New Member
- Joined
- May 17, 2020
- Messages
- 24
- Office Version
- 365
- 2016
- Platform
- Windows
Hello,
I hope all of you are healthy.
I have a word document that contains several chapters including assessments concerning various topics.
Since I have to update the document each week, I have tried to write a macro that deletes the contents of all chapters, but keeps the title of the chapter and therefore the structure of the document.
I have tried to use the macro-recorder, but because the length of the assessment varies each time, the macro does not work.
To solve my problem, I have inserted section breaks into my document that equal the text that should be deleted. The titles of the sections are excluded, so that they won´t be deleted.
The text of chapter 2.1 equals the 4th section as defined by my section breaks (continous).
I have then tried the following code (to delete the content of chapter 2.1 in my document = 4th section break)
Sadly, the macro does not work and the error " Run time error 5941: The requested member of the collection does not exist" appears.
Do you have ideas how to solve my problem and modify my macro?
Best regards and thanks in advance,
Sarah
I hope all of you are healthy.
I have a word document that contains several chapters including assessments concerning various topics.
Since I have to update the document each week, I have tried to write a macro that deletes the contents of all chapters, but keeps the title of the chapter and therefore the structure of the document.
I have tried to use the macro-recorder, but because the length of the assessment varies each time, the macro does not work.
To solve my problem, I have inserted section breaks into my document that equal the text that should be deleted. The titles of the sections are excluded, so that they won´t be deleted.
The text of chapter 2.1 equals the 4th section as defined by my section breaks (continous).
I have then tried the following code (to delete the content of chapter 2.1 in my document = 4th section break)
VBA Code:
Sub DeleteSectionnumber2point1()
Dim SECS As Word.Section
Set SECS = Selection.Sections(4)
SECS.Range.Select
SECS.Range.Delete
End Sub
Sadly, the macro does not work and the error " Run time error 5941: The requested member of the collection does not exist" appears.
Do you have ideas how to solve my problem and modify my macro?
Best regards and thanks in advance,
Sarah