Making Word documents independent of their linked templates - ms-word

At the office we are using several custom Word 2007 / 2010 templates. If we then send out doc files to clients they sometimes appear quite messy and ugly unformatted, as they do not have these templates on their machines.
Is there a way to embed templates into Word documents or kind of "flatten" these documents so they are not depending on the templates anymore and have formatting, images etc. all contained within just the Word doc file without needing the template anymore?
btw: I know printing the doc into a pdf and sending this would be a workaround, but we need to keep it in word, as clients have to be able to edit the documents.

This macro will break the link between a document and its template:
Sub DivorceFromTemplate()
' Dissassociates the document from its Word Template
With ActiveDocument
.UpdateStylesOnOpen = False
.AttachedTemplate = ""
End With
End Sub

Related

Copy from one Word document to another without breaking styling

We have two word documents, one that is used for as an order template and another that is our terms and conditions (T&C).
We would like to merge both documents into one without breaking the styling and have not been able to do so even with quite a considerable amount of effort.
Essentially, the T&C document has a bunch custom styles some of which overlap with the default word styles. This means that when copy pasting the T&C document into the order template, the result is a complete mess.
Is there a way of combining the two word files while maintaining the existing format (we would like the T&C to be copied into the Word document and not the other way around).
I have tried using the following Macro (found online) to remove the styles of the T&C document and maintain the format:
Sub DirectFormat()
Dim para As Paragraph
Dim fnt As Font
Dim pfmt As ParagraphFormat
For Each para In ActiveDocument.Paragraphs
With para
If .Style <> ActiveDocument.Styles("Normal") Then
Set fnt = .Style.Font
Set pfmt = .Style.ParagraphFormat
.Style = ActiveDocument.Styles("Normal")
.Range.Font = fnt
.Range.ParagraphFormat = pfmt
End If
End With
Next
End Sub
However after running it, the document looks completely different.
The simplest and most effective way is to ensure you don't have conflicting Style definitions and that the Style definitions in the source document, especially, haven't been overridden with direct formatting.
Other than that, instead of using copy/paste for content replication, you might use something like:
wdRngTgt.FormattedText = wdRngSrc.FormattedText
where wdRngTgt defines the destination range and wdRngSrc defines the source range.

Find or replace a string in word documents in a given folder

How to find or replace a word in the documents in the given folder
Is there is a tool or any script is available to do that?
Thanks.
Finding text is straightforward. There are several ways to do it, including using the Windows search utility. Here's an article with several methods: Search through the content of multiple Word documents
To find and replace, you can use a free text editor like Notepad++. It has a very good Find in Files utility. There are many other utilities that can do this, some paid and some free.
Finally, you can write a VBA macro that will find and replace all documents in a folder. Here's a page with a macro listing that does that: How to Find and Replace Contents in Multiple Word Documents

Idempotent Powershell word search/replace across documents with headers, change tracking, etc

I've found one or two guides to doing a word search and replace across multiple documents with powershell. They work well on simple documents. However, the script ignores text in headers and footers; and if "track changes" is enabled, it replaces text which has already been replaced, resulting in multiple copies of the new text if I run the script more than once on the same file.
Any clues as to how I can avoid these undesirable behaviors and make this script robust?
(reposted from Serverfault).
For replacing text in all parts of a Word document see:
Using a macro to replace text where ever it appears in a document

How can I insert OpenXML-Word files into another document programmatically in Word 2003

I need to insert an OpenXML Word document into another document in Word 2003 inside a VSTO 2005 customization.
With the old WordML (2003) documents I used Selection.InsertXML() for this, but OpenXML or the flat XML format (Flat OPC) of it does not work with this method in Word 2003 even if the compatiblity pack is installed (no surprise).
What options do I have to accomplish this?
Ernst
If the two file formats are incompatible with .InsertXML(), possibly try using VSTO to copy from the OpenXML document and paste into the WordML document. Hopefully the basic formatting of the document structure is retained after that operation.
The Word object model (which VSTO extends) has the Range.InsertFile method. You can use that to bring in the content of another Word document.

Auto-update pageref fields in rtf document

The application I'm working on outputs documents to rtf format and PAGEREF fields are used in a table of contents page and an index page. The problem is that on opening the document the fields do not update and remain blank. They work correctly if you manually update the fields in Word. Is there a way to make these fields auto-update in the RTF spec?
You could try to create a Document_Open() macro, although you might not be able to add a macro to an rtf file. You might be able to add a macro at a template (.dot) and have the .rtf file reference the template.
Private Sub Document_Open()
End Sub