|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active docume
Title:
ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active document is empty. Hi, I have created a Ribbon for MS Word(2010). On click of ribbon button(Download button) I have to open the document specified in the code. If active document(present document) is empty then it should open in same word instance and if the active document contains some text it should open in new word instance. I have the below piece of code which does this. Code:
private static void OpenWordDocument(byte[] content, string tempfile) { System.IO.File.WriteAllBytes(tempfile, content); object missing = System.Reflection.Missing.Value; object fileName = tempfile; object readOnly = true; object isVisible = true; object confirmConversions = true; object addToRecentFiles = false; object saveas = false; Microsoft.Office.Interop.Word.Document wordDoc = Globals.ThisAddIn.Application.Documents.Open( ref fileName, ref confirmConversions, ref readOnly, ref addToRecentFiles, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); ThisAddIn.Application.ActiveDocument.ActiveWindow.DisplayHorizontalScrollBar = true; ThisAddIn.Application.ActiveDocument.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView; } 1. Open saved word document which has some content in it. 2. Click on File tab -> New -> Blank document. 3. In this blank document, click on my Addin's download button which should download the content and display it in Word document. Since we have opened new blank document and this document is empty. It should have opened the downloaded content in this empty document itself instead it is getting displayed in new word instance. However the functionality works as expected when I first open the new document instead of saved word document in the first go.i.e, in below scenario: 1. Go to Start --> Select MS Word 2010. 2. In this blank document, click on my Addin's download button. This action downloads the content and display it in same blank document. Please help me to solve the above issue, thanks in advance. Regards, Chetan. |
#2
|
||||
|
||||
Cross-posted at: http://social.technet.microsoft.com/...ive?forum=word
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How do I active Inactive Application Add-ins in Word 2010? | Lebber | Word | 1 | 06-26-2014 06:11 AM |
Detecting an active instance of Excel from Word VBA | Sorcerer13 | Word VBA | 17 | 06-02-2014 02:48 AM |
Open new instance for each file | a3ng25 | Office | 1 | 01-28-2013 06:47 AM |
trying to open a word 2010 document and opens the file conversion window | starfish | Word | 2 | 05-24-2012 12:06 AM |
Open source DDE test methods? | d.rock90 | Excel Programming | 1 | 01-05-2011 12:03 PM |