Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-24-2018, 02:34 PM
ArtKilp ArtKilp is offline Inserting a QuickPart from Normal.dotm using C# interop? Windows 8 Inserting a QuickPart from Normal.dotm using C# interop? Office 2016
Novice
Inserting a QuickPart from Normal.dotm using C# interop?
 
Join Date: Jan 2016
Posts: 18
ArtKilp is on a distinguished road
Default Inserting a QuickPart from Normal.dotm using C# interop?

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
Reply With Quote
  #2  
Old 07-24-2018, 02:58 PM
ArtKilp ArtKilp is offline Inserting a QuickPart from Normal.dotm using C# interop? Windows 8 Inserting a QuickPart from Normal.dotm using C# interop? Office 2016
Novice
Inserting a QuickPart from Normal.dotm using C# interop?
 
Join Date: Jan 2016
Posts: 18
ArtKilp is on a distinguished road
Default

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);
Reply With Quote
Reply

Tags
c#, interop, quickparts

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Inserting a QuickPart from Normal.dotm using C# interop? Won't load Normal.dotm rwsinky Word 2 10-09-2016 02:38 PM
Inserting a QuickPart from Normal.dotm using C# interop? Can't find Normal.dotm Ajeeja Word 8 08-14-2014 07:36 AM
Inserting a QuickPart from Normal.dotm using C# interop? Open Quickpart file normalemail.dotm - edit multiple building blocks rollno Word 7 02-24-2014 04:29 PM
Inserting a QuickPart from Normal.dotm using C# interop? New template/New normal.dotm kenglade Word 3 12-19-2011 04:00 PM
Inserting a QuickPart from Normal.dotm using C# interop? How to get to normal.dotm Aiken_Bob Word 4 05-02-2011 02:41 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:13 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft