![]() |
|
#1
|
|||
|
|||
|
I made a QuickPart to Normal.dotm and now I want to place it to the document
(where the cursor is) using C# interop. The basics (create application, create document, locate cursor etc.) doesn't need to be covered, I know those, but how does the beef of that work like? Here's the same as "pseudocode" Word.Document ActiveDoc = Globals.ThisAddIn.Application.ActiveDocument; Word.Selection selected = Globals.ThisAddIn.Application.Selection; Word.Range rng = selected.Range; rng.AddQuickPart("Normal.dotm", "ThePartIJustCreated"); //This one obviously doesn't work |
|
#2
|
|||
|
|||
|
Found it:
private static BuildingBlock GetQuickPartFromTemplate(Microsoft.Office.Interop. Word.Application wordApplication, string wordTemplateDocumentPath, object quickPartName) { return (from Template template in wordApplication.Templates where template.FullName.Contains(Path.GetFileNameWithout Extension(wordTemplateDocumentPath)) let index = quickPartName select template.BuildingBlockEntries.Item(ref quickPartName)).FirstOrDefault(); } https://stackoverflow.com/questions/...s-using-c-shar You can call it like: string temp = Environment.GetFolderPath(Environment.SpecialFolde r.ApplicationData) + @"\Microsoft\Templates"; BuildingBlock b = GetQuickPartFromTemplate(doc.Application, temp + "\\Normal.dotm", "ThePartIJustCreated"); Range rng = doc.Application.Selection.Range; rng = b.Insert(rng); |
|
| Tags |
| c#, interop, quickparts |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Won't load Normal.dotm
|
rwsinky | Word | 2 | 10-09-2016 02:38 PM |
Can't find Normal.dotm
|
Ajeeja | Word | 8 | 08-14-2014 07:36 AM |
Open Quickpart file normalemail.dotm - edit multiple building blocks
|
rollno | Word | 7 | 02-24-2014 04:29 PM |
New template/New normal.dotm
|
kenglade | Word | 3 | 12-19-2011 04:00 PM |
How to get to normal.dotm
|
Aiken_Bob | Word | 4 | 05-02-2011 02:41 PM |