How to apply macro at end of every heading in MS Word?

眉间皱痕 提交于 2019-12-24 02:40:25

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!