VBA macro to find all instances in a doc of a string, e.g., "a dog", and insert in tracked a reference numeral, e.g., "(102)", immediately afterwards

Advertisements I’d like a VBA macro in word to find all instances of a user-selected string in a document (e.g., "a dog") and insert a corresponding user-selected reference numeral in parentheses (e.g., "(102)") immediately following each string. I have made a find-and-replace style macro but, in tracked changes, it shows as artificial revisions the deletion… Read More VBA macro to find all instances in a doc of a string, e.g., "a dog", and insert in tracked a reference numeral, e.g., "(102)", immediately afterwards

How to extract sentences containing any of several words using Word VBA

Advertisements I have a Microsoft Word file, Tst.doc that contains the following sentences: Sofa 1. Sofa 2. Chair 1. Chair 2. Seat 1. Seat 2. I need to extract all the sentences containing any of the words (sofa,chair,seat) to a second file named OutputBin.doc that is stored in a fixed location. I wrote the following… Read More How to extract sentences containing any of several words using Word VBA

how to export images to word file?

Advertisements I am working on a script which saves images to word file. I have been able to create a function to export images. def exp_images(): #export images to word file document = Document() paragraph = document.add_paragraph() script = paragraph.add_run() script.add_text(‘This is a test sentence’) script.add_picture(‘image1.png’, width=Inches(6.5)) document.save(‘demo.docx’) if __name__ == "__main__": exp_images() The only… Read More how to export images to word file?

Count words in a Microsoft Word document by document style?

Advertisements In analogy to this question, I would like to script a VBA script that counts words formatted with a certain document style, more precisely: a certain paragraph style. Sub CountTypeface() Dim lngWord As Long Dim lngCountIt As Long Const Typeface As String = "Calibri" Const MyFormat As String = "My Paragraph Style" ‘Ignore any… Read More Count words in a Microsoft Word document by document style?