Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-22-2014, 02:42 AM
chetan rajakumar chetan rajakumar is offline ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active docume Windows 7 32bit ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active docume Office 2010 32bit
Novice
ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active docume
 
Join Date: Aug 2014
Posts: 1
chetan rajakumar is on a distinguished road
Default 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;
}
Issue: The functionality does not work expected in below scenario:
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.
Reply With Quote
  #2  
Old 08-23-2014, 03:52 AM
macropod's Avatar
macropod macropod is offline ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active docume Windows 7 64bit ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active docume Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
ThisAddIn.Application.Documents.Open() methods opens new word instance even though the active docume 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:17 PM.


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