问题
I have a document with various headings (so not necessarily Heading 1 or Heading 2 - but all types of headings).
What I'm trying to do is write a macro that will, for example, delete 2 spaces at the end of each heading.
For example, we have
This is a heading
At the end of heading, I will do:
Selection.Delete Unit:=wdCharacters, Count:=2
I need this to be applied at the end of each heading.
Does anyone know how to do this?
回答1:
Goto first heading:
Selection.GoTo What:=wdGoToHeading,Which:=wdGoToFirst
Goto next heading
Selection.GoTo What:=wdGoToHeading,Which:=wdGoToNext
Check where you are to see if you have reached the last heading:
x=Selection.Start
Selection.GoTo What:=wdGoToHeading,Which:=wdGoToNext
if x = Selection.Start then '... last heading reachd
Goto end of current heading (for example, to delete chars:
Selection.EndKey Unit:=wdLine
来源:https://stackoverflow.com/questions/1801334/how-to-apply-macro-at-end-of-every-heading-in-ms-word