I use this code to replace word file's some words with vb.net windows application text boxes values.

 'use early binding
        Dim objWordApp As Word.Application = Nothing
        Try
            objWordApp = New Word.Application
            'Open an existing document.

            objWordApp.Documents.Open("C/temp/word.docx")
            'copy data to clipboard
            txtFirstName.SelectAll()
            txtFirstName.Copy()
            'find <address>
            objWordApp.Selection.Find.Execute("<address>")
            'copy richtext from clipboard
            objWordApp.Selection.PasteSpecial(DataType:=Word.WdPasteDataType.wdPasteText)
            'clear the clipboard
            Clipboard.Clear()
            'Save and close the document.
            objWordApp.Documents.Item(1).Save()
            objWordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            'quit Word
            If Not IsNothing(objWordApp) Then
                objWordApp.Quit()
                objWordApp = Nothing
            End If
        End Try

But Now I want to open and select word file by open file dialogue. Currently I coded where word file located.
And also want to save new edited word file to other location by save file dialogue. Can anyone help me ?

The classes involved are OpenFileDialog and SaveFileDialog. Basically instantiate a new instance of each class and use the ShowDialog() method to show it. The Filename property contains the filename opened, or saved.

This article has been dead for over six months. Start a new discussion instead.