

Step 3) Create Pre-Defined bookmarks to the document where attachments need to be embedded Step 2) Create a temp folder and store these attachments in this temp folder Step 1) Retrieve the attachment file from the SharePoint Document library here as example is pagenumber.We took the below approach to achieve the requirement of embedding attachment to the Document using bookmark as the parameter to the Embed function 'bmark name would have added info of page, line, and col number. MySent.Information(wdFirstCharacterColumnNumber), Range:=MySent) MySent.Information(wdFirstCharacterLineNumber) & "_" & _ I've added some code for naming the bookmarks, as well. It's not necessary to loop the collection of bookmarks - espeicially since there aren't any - they're being added. I left it in since it is declared in the code in the question. If you won't be doing anything else with the bookmark, it's not strictly necessary to Set bkm = when adding the bookmark. This provides the target Range for the Bookmarks.Add method. This will force you to declare ("Dim") variables, but will also save time and trouble as it will prevent typos and warn you of other problems.Ī Sentence in Word returns a Range object, so the code below delares MySent As Range. Please remember to put Option Explicit at the top of a code page. The following works for me, as far as the requirements in the question go. here as example is pagenumber.ĮXPECTED RESULT: Within entire document, each sentence has a corresponding bookmark and bookmark name ("bmarkpg01ln01col01", "bmarkpg01ln02col10", etc.)ĪCTUAL RESULTS: only one bookmark is added to the first sentence of the document. Sub tryAddBmarkatSentence()įor Each MySent In ActiveDocument.Sentencesįor Each bmark In ActiveDocument.BookmarksĪ Name:="pmark" & (wdActiveEndAdjustedPageNumber), Range:=myRange 'bmark name would have added info of page, line, and col number.

I've tried a for each loop to attempt each sent in sentences and each bmark in bookmark. My code adds only one bookmark to first sentence and doesn't loop through to end of document. For example, at first sentence would be bookmark "bmarkpg01" and second sentence would be bookmark ""bmarkpg01ln01col01"". Within a Word docx: I'm trying to add a bookmark to each sentence.
