| Code level: advanced Code area: Outlook Expert Techniques Printer Friendly Version | ||
| Title: OL2007: Insert QuickPart | ||
| Description: Demonstrates how to return the insertion point (Word.Selection) from an open Outlook item and insert a Quick Part. Requires Word 2007. | ||
| Date: 26-Mar-2007 09:42 | ||
| Code level: advanced | ||
| Code area: Outlook Expert Techniques | ||
| Posted by: Sue Mosher | ||
| Body: |
||
| All 18comments |
| Page [ 1 2 Next >> ] | ||
|
|
Sue Mosher
26-Mar-2007 11:30
This VBA code assumes you have the item open. Call the procedure with the name of the Quick Part: Call InsertQuickPart("Part Name") The VBScript version for use behind an Outlook form would look like this: Sub InsertQuickPart(strPartName As String) Dim objDoc ' As Word.Document Dim objWord ' As Word.Application Dim objSel ' As Word.Selection Dim objETemp ' As Word.Template On Error Resume Next Set objDoc = Item.GetInspector.WordEditor Set objWord = objDoc.Application Set objSel = objDoc.Windows(1).Selection Set objETemp = objWord.Templates(1) objETemp.BuildingBlockEntries(strPartName).Insert _ objSel.Range, True Set objDoc = Nothing Set objWord = Nothing Set objSel = Nothing Set objETemp = Nothing End Sub |
|
|
|
Neil Goundar
10-Apr-2007 18:26
Hello Sue, Is there an easy way in Outlook 2007 to Insert the contents of one e-mail into a new one that I am composing (programatically)? Here is what I need to do exactly in Outlook 2007: - I display a list of e-mails in a folder the user picks to the user. The e-mail picked then needs to be inserted into the e-mail that I am composing at the current cursor location. Also the formatting of the text to be inserted needs to be kept. Thanks for any help, Neil |
|
|
|
Sue Mosher
15-Apr-2007 12:05
Neil, you'd use a similar technique to this sample -- getting a Word.Document object and then using Word methods (which you can use the Word macro recorder to help you with). |
|
|
|
ron botman
24-Sep-2007 02:01
Hello Sue, Is it possible to insert perform the above from VSTO? I have got the code working upto the point of referencing the Word.Application.Window and got stuck on the passing a ref to the Windows Index. Ron. |
|
|
|
Sue Mosher
24-Sep-2007 06:20
Ron, it certainly should be possible. Could you post a code snippet that shows where you're having a problem? |
|
|
|
ron botman
25-Sep-2007 00:39
Sue, The code in the Outlook AddIn looks like this: Inspector thisInspector = Globals.ThisAddIn.Application.ActiveInspector(); Word._Document document = (Word._Document)thisInspector.WordEditor; Word._Application wordApp = document.Application; Word.Selection selection = wordApp.Windows[1].Selection; selection.InsertAfter("Hello world"); The AddIn requires a reference to Word 12 Object Library. The line that is causing the trouble is: Word.Selection selection = wordApp.Windows[1].Selection; It wants the index to Windows to be passed by ref. Attempting to create a pointer, I get a 'Cannot use unsafe construct in safe context' error. I have tryed using ActiveWindow, it compiles and runs but there is no output. Ron. |
|
|
|
Sue Mosher
25-Sep-2007 06:45
Unfortunately, I don't write C# code, so I don't understand why the index needs to be passed by ref or what would resolve that. ActiveWindow definitely won't work. That's why you have to go through the Windows collection. Can you iterate that collection and work with the first window? There should be only one. |
|
|
|
ron botman
26-Sep-2007 08:02
Sue, Yes, iterating through the Windows collection did work. Thanks for your help. Ron. |
|
|
|
Sue Mosher
26-Sep-2007 08:13
Great! Now we know how to make the technique work OK for C#. That's very useful information. Thanks. |
|
|
|
Himanshu
12-Dec-2007 09:01
Hello All, I want to send an e-mail with image URL in the HTML body so that when the recepient opens that e-mail, Images get downloaded from the server. It was working in Outlook 2003 but not in Outlook 2007. In OL 2007, images are Inserted physically before the e-mail is sent to the recepient. Please suggest |
|
| Page [ 1 2 Next >> ] | ||
| Post your comment name email |
