by Gehan Fernando (47 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Tue 21st October 2008
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Open protected Or non protected documents using vb.net
API Declarations
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Word
Private word_app As Word.Application
Private word_doc As Word.Document
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
word_app = New Word.Application()
word_doc = New Word.Document()
' Open non protected doc file
word_doc = word_app.Documents.Open("C:\My_Test_Apps\Test\Hello World.doc")
' Open protected doc file
Dim password As Object = System.Reflection.Missing.Value
password = "123456"
word_doc = word_app.Documents.Open("C:\My_Test_Apps\Test\Protected_File.doc", , , , password, , , , , , , , , , , )
word_app.Visible = True
End Sub
Private Sub FormOpenDoc_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
word_app = Nothing
End Sub
End Class