
'oDoc.SelectContentControlsByTag("Content control tag")(1).Range. SourceDoc = (SourceFile)ĭoc.SelectContentControlsByTag("Content control tag")(1).Range.PasteSpecial(DataType:=) Are you able to reproduce these steps without using a macro What are your results from. If System.IO.File.Exists(SourceFile) Then I know that copy-pasting into Word manually can cause similar issues. OWord1 = CreateObject("Word.Application")ĭim SourceFile As String = "Some.docx" 'Varies
/001-insert-source-code-into-word-document-3994582-1a2d127c226f4846bf9bec7d9a281fc5.jpg)
' - Create another instance of word for reading/copying and closing without closing our main word application Simplified code so far (in vb.net languange): Dim oWord As Word.Application In order to retain the formatting that you want to keep, open the Find/Change dialog box by choosing Edit > Find/Change. Picture of how it currently creates it (using "MatchDestinationFormatting")": "NOTE!" is missing, and the content controls in table has been removed. I want to keep the template formatting so that the chapters and paragraphs will be in sequence, but some of the source text I copy over have its own formatting (like background/text color etc.) that I need to keep as well.įor info, I'm using VB.net and not VBA (I can translate VBA to VB.net), but theres a higher chance this subreddit knows how to do it.


I have a word template with content controls that I'm filling out programmatically with other word documents.
