Results 1 to 3 of 3

Thread: Open MS Word document using VB.NET

  1. #1
    Join Date
    Dec 2008
    Posts
    19

    Open MS Word document using VB.NET

    Hello,

    How can I open MS Word document using VB.NET?

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Open MS Word document using VB.NET

    Below is the code to open Word document.

    Code:
    Private Sub button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) '
    ' Use the custom dialog to get the title of the document from the user
    Dim theQueryDialog As New TitleQuery
    If theQueryDialog.ShowDialog() = DialogResult.OK Then
    
    Dim missing As Object = System.Reflection.Missing.Value
    Dim fileName As Object = "normal.dot"
    ' template file name
    Dim newTemplate As Object = False
    Dim docType As Object = 0
    Dim isVisible As Object = True
    ' Create a new Document, by calling the Add function in the Documents collection
    Dim aDoc As Word.Document = WordApp.Documents.Add(fileName, newTemplate, docType, isVisible)
    ' need to see the created document, so make it visible
    WordApp.Visible = True
    aDoc.Activate()
    ' Global Constant enumerations are members of Word and can beassignedproperties
    ' Set alignment to the center of the document WordApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
    ' Toggle the title to a Bold Font
    WordApp.Selection.Font.Bold = CInt(Word.WdConstants.wdToggle)
    End If ' Type the Text of the Title that was inputted by the user in the CustomDialog WordApp.Selection.TypeText(theQueryDialog.Title); }}
    End Sub 'button2_Click

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Open MS Word document using Asp.NET

    This given code is to Open MS Word document using Asp.NET

    Code:
    Try
                Dim stream As FileStream = File.Open("d:\word.doc", FileMode.Open) 'replace the location with your word doc.
    
                stream.Position = 0
    
                ' Now read s into a byte buffer.
                Dim bytes() As Byte = New Byte(stream.Length) {}
                Dim numBytesToRead As Integer = CType(stream.Length, Integer)
                Dim numBytesRead As Integer = 0
                While numBytesToRead > 0
                    ' Read may return anything from 0 to numBytesToRead.
                    Dim n As Integer = stream.Read(bytes, numBytesRead, numBytesToRead)
                    ' The end of the file is reached.
                    If n = 0 Then
                        Exit While
                    End If
                    numBytesRead += n
                    numBytesToRead -= n
                End While
                stream.Close()
    
                Response.Clear()
                Response.ContentType = "application/word"
                Response.AddHeader("Content-disposition", "filename=output.doc")
    
                Response.OutputStream.Write(bytes, 0, bytes.Length)
                Response.OutputStream.Flush()
                Response.OutputStream.Close()
                Response.Flush()
                Response.Close()
            Catch ex As Exception
                Throw ex
            End Try

Similar Threads

  1. Word cannot open document
    By Scotty816 in forum Windows Software
    Replies: 1
    Last Post: 03-10-2011, 12:16 PM
  2. Open MS Word Document From JSP Page
    By samualres in forum Software Development
    Replies: 5
    Last Post: 12-03-2010, 04:20 PM
  3. How to open a word document by a chapter
    By Carlee in forum Windows Software
    Replies: 3
    Last Post: 04-09-2009, 08:57 PM
  4. Cannot open word document in Mail Mac OS
    By Jason Bourne in forum Operating Systems
    Replies: 3
    Last Post: 09-05-2009, 05:18 PM
  5. Word 2003 does not open document
    By JanP in forum Windows Software
    Replies: 8
    Last Post: 26-03-2009, 07:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,471,486.76436 seconds with 17 queries