Home > Net >  Opening Word Doc From DblClck event on Listbox
Opening Word Doc From DblClck event on Listbox

Time:10-13

I'm having some strange issues getting my code to work. I'm trying to use a double click event on my list box SOPList to open the selected word document. It runs fine the first time you double click a document in the list but the next time you double click the document it gives the error: "The remote server machine does not exist or is unavailable". The error is on line Documents.Open FileToOpen to open the document.

While the location is a network drive it is still visible and connected. I'm not sure what I'm missing and I'm hoping a second set of eyes can help me figure it out.

Code:

Private Sub SOPList_DblClick(Cancel As Integer)
Dim FilePath As String
Dim FileName As String
Dim FileToOpen As String
Dim objWord As Word.Application

    Set objWord = CreateObject("Word.Application")
      
        If SOPList.ListIndex > -1 Then
          FilePath = "\\page\data\NFInventory\groups\CID\SOPs\"
          FileName = Me.SOPList.Value
          FileToOpen = FilePath & FileName
    
          Documents.Open FileToOpen '<---error line
        End If
        
        objWord.Visible = True
        Set objWord = Nothing
    
    End Sub

Thank you!!

CodePudding user response:

Try changing

Documents.Open FileToOpen

to

objWord.Documents.Open FileToOpen
  • Related