Has this ever happened to you? You are writing a big image heavy test report or user document in Microsoft word. And as you get to the end of your job, you suddenly realise you forgot to caption your images in the document.
You get angry on yourself at the prospect of spending an extra hour to correct this oversight.
Well a similar thing happened recently. And when I thought about it, it had happened more than I want to reveal here. Since writing report isn’t a daily activity of my job, this thing reoccurs. After a hundred and odd page, I go back and add caption to the pictures that I forgot in the first place.
So this time, instead of fixing the captions, I spent the next hour experimenting, how to fix the mess and came up with the following VBA script to add auto captions to images in a word document.
Simple script. Posting it here in case if someone is in similar situation.
Sub CaptionPictures() Dim objPic As InlineShape For Each objPic In ActiveDocument.InlineShapes objPic.Select Selection.InsertCaption Label:="Figure", TitleAutoText:="", Title:="", _ Position:=wdCaptionPositionBelow, ExcludeLabel:=0 Next objPic End Sub