Replacing captions in Word documents with automated numbering, using VBA macro

StackOverflow https://stackoverflow.com/questions/9045171

  •  03-12-2019
  •  | 
  •  

سؤال

I have a large MS Word document with a lot of captions named like this: "Map X. Map title.". The problem is that the "X" are not in ascending order. I'd like to fix it running VBA macro that will replace the "X" to a right number.

I have no problem with replacing strings but I would like to know what should I replace the "X" with (what is the type of object associated with automated numbering).

The numbers will go up for every type of Caption (e.g. "Map", "Chart"), without restarting inside chapters.

هل كانت مفيدة؟

المحلول

Okay, I found something that might help. There is a type of Field that you can add that will create a automatic number sequence for a given reference. So will we take your example above "Map X. Map title", if you can set you code to select 'X' and then follow it with...

MyRef = "Map"
Selection.Fields.Add(Selection.Range, , "SEQ " & MyRef, False).Update

Once that's done you may need to press ALT+F9, to hide/show the Field codes

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top