2
Dim myStream As Stream = Nothing
Dim openFileDialog1 As New OpenFileDialog()
openFileDialog1.InitialDirectory = "C:\Temp"

If openFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
    Try
        myStream = openFileDialog1.OpenFile()
        If (myStream IsNot Nothing) Then
            Dim oWord As Word.Application
            Dim oDoc As Word.Document
            Dim oPara1 As Word.Paragraph
            oWord = CreateObject("Word.Application")
            oWord = New Word.Application
            oWord.Visible = True
            oDoc = oWord.Documents.Add

            'Open an existing document.

            oWord.Documents.Open(openFileDialog1.FileName, ReadOnly:=False)
            oDoc = oWord.ActiveDocument

            'Insert a paragraph at the beginning of the document.

            oPara1 = oDoc.Content.Paragraphs.Add
            oPara1.Range.Text = "Heading 1"
            oPara1.Range.Font.Bold = True
            oPara1.Format.SpaceAfter = 24    '24 pt spacing after paragraph.
            oPara1.Range.InsertParagraphAfter()
        End If

    Catch Ex As Exception
        MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
    Finally

    ' Check this again, since we need to make sure we didn't throw an exception on open.

        If (myStream IsNot Nothing) Then
            myStream.Close()
        End If
    End Try
End If

When I run this section of the program, the word document opens, but it opens in read-only mode. How do I ensure that the document is opened in edit mode from the code?

Screenshot

T54
  • 81
  • 1
  • 16
annee
  • 23
  • 4

0 Answers0