views:

96

answers:

1

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?

A: 

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
Doc Brown