none
Opening a MS Word document RRS feed

All replies

    • Proposed as answer by simonb549 Monday, February 24, 2020 8:59 AM
    Sunday, February 23, 2020 7:54 AM
  • I am atempting to use this code, with a few problems.  Please help

    Private Sub TestButton_Click(sender As Object, e As EventArgs) Handles TestButton.Click
    
            Documents.Open(FileName:="C:\MyFiles\MyDoc.doc", ReadOnly:=True)
    
        End Sub

    The first problem is "Documents" is not declared, how do I do this?

    The second is I do not want to open a document directly, I need to use a variable and Listbox selected Item.

    Dim HoofgeregteFolder As String = "M:\My Documents\My Resepte\Hoofgeregte\Heerlike Sop Resepte"

    Documents.Open(FileName: = HoofgeregteFolder, Me.TitleListBox.SelectedItem.ToString, ReadOnly:=True)

    Sunday, February 23, 2020 8:46 AM
  • Add a reference to Microsoft Word Object Library, as explained in one of the MS samples : 

    How to automate Word...

    or on some sites like (in C#, but same thing as in VB.NET) : Word automation using C#


    • Edited by Castorix31 Sunday, February 23, 2020 9:23 AM
    Sunday, February 23, 2020 9:09 AM
  • How about using System.Diagnostics.Process?

    Dim p As System.Diagnostics.Process = _
        System.Diagnostics.Process.Start("C:\test\test.docx")

    Regards,


    Ashidacchi -- http://hokusosha.com

    Monday, February 24, 2020 3:38 AM
  • I have tryed the code as is. it works perfectly.  

    Using it in my app like this it opens the folder contyning the document.  

    My listbox does not shoe the file extention, that might be the problem.  

    One more thing, I would prefer the document open as read only.

    RecipeFolder = "M:\My Documents\My Resepte\Gebottelde & Ander Ingelegde Lekerneie\Smeere & Bladjang"
    
    Dim p As System.Diagnostics.Process = System.Diagnostics.Process.Start(RecipeFolder, Me.RecipeListBox.SelectedItem.ToString)


    Monday, February 24, 2020 8:45 AM