Help with Integrating MS Word in VB.NET
-
I am making an appliaction where i need to open a file and save it in different place. Now the file type is .doc, so i need to open the file in MS Word (Its a stand alone application and user may use MS Word 2003 or 2007), with in the application or out side the application, till now i am comfortable to do. The problem raises when its time to save the application. When i am trying to save it through MS Word, it actually show the save dialog box. Which has to be blocked as i need to save the file only at one particular location, through code. Can any one tell me how to block Save button (New and Open are always bloked by default) (OR) block Standard tool bar in MS Word. And to block Menu bar in MS Word. Any help would be greet... It very urgent please help me...
Jats
-
I am making an appliaction where i need to open a file and save it in different place. Now the file type is .doc, so i need to open the file in MS Word (Its a stand alone application and user may use MS Word 2003 or 2007), with in the application or out side the application, till now i am comfortable to do. The problem raises when its time to save the application. When i am trying to save it through MS Word, it actually show the save dialog box. Which has to be blocked as i need to save the file only at one particular location, through code. Can any one tell me how to block Save button (New and Open are always bloked by default) (OR) block Standard tool bar in MS Word. And to block Menu bar in MS Word. Any help would be greet... It very urgent please help me...
Jats
-
Hi can you post the code you're using to save the file. I might be able to help with that.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
Here is the code to save the contents in a different file... Here is the code, Add reference to Microsoft Word 11.0 Library
Imports Microsoft.Office.Interop.Word Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient Imports System.Configuration Public Class form1 Dim WithEvents wordApp As New Microsoft.Office.Interop.Word.Application Dim WithEvents doc As New Microsoft.Office.Interop.Word.Document Dim strSaveFile As String = "C:\Test\Retrive_the_data.doc" Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 'Create a Word App wordApp.Visible = False With wordApp .Documents.Open(strSaveFile) 'Clipboard.SetText("lpt ", TextDataFormat.Text) 'wordApp.Selection.InsertParagraph() 'wordApp.Selection.Paste() Dim strsaveasfile As String = "c:\Test\retry.doc" Try If (strSaveFile <> String.Empty) And (Not (IsNothing(strSaveFile))) Then .ActiveDocument.SaveAs(strSaveFile) .ActiveDocument.SaveAs(strsaveasfile) End If Catch ex As Exception MsgBox(ex.Message) End Try .Visible = True .Activate() End With System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp) End Sub End Class
Now i just have to deactivate the Save as button in MS Word. And if it is possible i would also like to block Title bar and Menu bar.Jats
modified on Friday, April 18, 2008 8:23 AM
-
Here is the code to save the contents in a different file... Here is the code, Add reference to Microsoft Word 11.0 Library
Imports Microsoft.Office.Interop.Word Imports System.Data Imports System.Data.OleDb Imports System.Data.SqlClient Imports System.Configuration Public Class form1 Dim WithEvents wordApp As New Microsoft.Office.Interop.Word.Application Dim WithEvents doc As New Microsoft.Office.Interop.Word.Document Dim strSaveFile As String = "C:\Test\Retrive_the_data.doc" Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 'Create a Word App wordApp.Visible = False With wordApp .Documents.Open(strSaveFile) 'Clipboard.SetText("lpt ", TextDataFormat.Text) 'wordApp.Selection.InsertParagraph() 'wordApp.Selection.Paste() Dim strsaveasfile As String = "c:\Test\retry.doc" Try If (strSaveFile <> String.Empty) And (Not (IsNothing(strSaveFile))) Then .ActiveDocument.SaveAs(strSaveFile) .ActiveDocument.SaveAs(strsaveasfile) End If Catch ex As Exception MsgBox(ex.Message) End Try .Visible = True .Activate() End With System.Runtime.InteropServices.Marshal.ReleaseComObject(wordApp) End Sub End Class
Now i just have to deactivate the Save as button in MS Word. And if it is possible i would also like to block Title bar and Menu bar.Jats
modified on Friday, April 18, 2008 8:23 AM
I see what you're trying to do. As far as I know what you're trying to do is pretty impossible. But what you can do is that you can change read only property.
With wordApp
.Documents.Open(strSaveFile, , True)That parameter makes your document READ ONLY, but you cannot block save box. By looking at code, it seems like you want something that user can only read but not change right? If this is a case then why not convert your doc to PDF and then show that!! They wont be able to do anything.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
-
I see what you're trying to do. As far as I know what you're trying to do is pretty impossible. But what you can do is that you can change read only property.
With wordApp
.Documents.Open(strSaveFile, , True)That parameter makes your document READ ONLY, but you cannot block save box. By looking at code, it seems like you want something that user can only read but not change right? If this is a case then why not convert your doc to PDF and then show that!! They wont be able to do anything.
- Stop thinking in terms of limitations and start thinking in terms of possibilities -
Actually thats not what i want to do. The operation i want to perform is to open a document from a location say 'loc1' and after making the changes save it to 'loc2' but both locations have to be handled by Application I cannot allow user to save it in another location as if it is done I cannot track the documents for generating final report combining all the docs. So what i am actually doing is i am taking the input file (doc1) from loc1 and saving it as doc2 in loc2. And then oppening doc2 from loc2 so that user can make changes and click save. and it just updates the present document that is... Doc2 in Loc2. Thats all... But in case the user makes save as operation then it will lead to problem while generating reports... Basically Doc1 and soon in Loc1 are templates and Doc2 and soon in Loc2 are mofiled files related to a particular project.
Jats