RIAS
asked on
Open a word document
Hello,
How can I open a word document from vb.net desktop app.
Also,if a word object is created ,please let me know how to close it (instance created only by the project )without leaving a instance in the task manager.
Cheers
How can I open a word document from vb.net desktop app.
Also,if a word object is created ,please let me know how to close it (instance created only by the project )without leaving a instance in the task manager.
Cheers
ASKER
pawan,
How to dispose of objword?
How to dispose of objword?
Try setting the object to Nothing.
ASKER
This still leaves a instance in my task manager
Try this..
Dim oWord As Word.Application
Dim oDoc As Word.Document
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add("E:\\Pawan.doc")
oDoc.Quit(Word.WdSaveOptions.wdSaveChanges)
oDoc = Nothing
ASKER
Pawan,
Thanks.
oWord needs to be quit . It leaves a istance in task manger.
Thanks.
oWord needs to be quit . It leaves a istance in task manger.
Not worked?
ASKER
Nope
ASKER
Please refer to my question :
https://www.experts-exchange.com/questions/28987463/Close-word-object.html
https://www.experts-exchange.com/questions/28987463/Close-word-object.html
Try to Close the ActiveDocument as well:
oDoc = oWord.Documents.Add("E:\\P awan.doc")
oDoc.ActiveDocument.Close( Word.wdSav eOptions.w dSaveChang es)
oDoc.Quit(Word.WdSaveOptio ns.wdSaveC hanges)
oDoc = Nothing
https://msdn.microsoft.com/en-us/library/af6z0wa2.aspx?f=255&MSPPError=-2147217396
oDoc = oWord.Documents.Add("E:\\P
oDoc.ActiveDocument.Close(
oDoc.Quit(Word.WdSaveOptio
oDoc = Nothing
https://msdn.microsoft.com/en-us/library/af6z0wa2.aspx?f=255&MSPPError=-2147217396
try this..
Imports System.IO
Imports System.Net.Mime.MediaTypeNames
Imports System.Diagnostics.Process
Imports Microsoft.Office.Interop
Public Class Form1
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim oWord As Word.Application
Dim oDoc As Word.Document
oWord = CreateObject("Word.Application")
oWord.Visible = True
oDoc = oWord.Documents.Add("E:\\Pawan.doc")
KillProcess("Winword")
End Sub
Private Sub KillProcess(processName As String)
Dim myproc As New System.Diagnostics.Process()
For Each thisproc As Process In Process.GetProcessesByName(processName)
If thisproc.CloseMainWindow() Then
thisproc.Kill()
End If
Next
End Sub
End Class
Give DocX a try
https://docx.codeplex.com/
DocX is a .NET library that allows developers to manipulate Word 2007/2010/2013 files, in an easy and intuitive manner. DocX is fast, lightweight and best of all it does not require Microsoft Word or Office to be installed.
https://docx.codeplex.com/
Hi Rias,
Any luck :) ?
Regards,
Pawan
Any luck :) ?
Regards,
Pawan
ASKER
Pawan,
Just trying now...gimme a minute...
Just trying now...gimme a minute...
Just know that after a few kill, Word will want to open in safemode
ASKER
Pawan,
It killed all the word documrnts including the ones not opened by app .
Thanks
It killed all the word documrnts including the ones not opened by app .
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Pawan,
Just a simple twick, can you please open any other word document and then try your code.
Please let me know if the other document closes as well .
Cheers
Just a simple twick, can you please open any other word document and then try your code.
Please let me know if the other document closes as well .
Cheers
Hi Rias,
I tired that case, it is working on my machine. It is not closing other word documents, You can try out.
Regards,
Pawan
I tired that case, it is working on my machine. It is not closing other word documents, You can try out.
Regards,
Pawan
ASKER
ok, will try here.
I guess the difference is my word object is global .
I guess the difference is my word object is global .
ASKER
Pawan,
I need to use
oWord = GetObject("Word.Applicatio n")
as I am doing mail merge of many documents.
I create my object on form load and then use it by getobject .
I need to use
oWord = GetObject("Word.Applicatio
as I am doing mail merge of many documents.
I create my object on form load and then use it by getobject .
ASKER
Tried it and it worked!!!!
ASKER
Thanks a ton!
Open in new window
Ref - http://www.authorcode.com/how-to-open-existing-word-document-in-vb-net/