Closing a word file?

P

pgoodale

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)

' Linking Word Documents to certain cells within the LM_INDEX
' Code written by:
' Paul Goodale
' ------------


' Declaring Variables

Dim intResponse As Integer
Dim WrdApp As Object
Dim Msg, Style, Title

On Error GoTo Ignore

Cell = Target

'Declaring Variables for the Message Box
Msg = "Would you like to view " & Target & " ?"
Style = vbYesNo + vbQuestion
Title = "Open BOM file"

If Left(Target, 2) = "LM" Then
frmOpenLM.Show vbModal
Exit Sub

' Determines whether the cell has a BOM# within it
ElseIf Left(Target, 3) = "BOM" Then

' Displays a message box with variable options
intResponse = MsgBox(Msg, Style, Title)

' Selects the outcome if 'Yes' is chosen
If intResponse = vbYes Then

Set WrdApp = CreateObject("Word.Application")

' Opens Word file
With WrdApp

' Searches for Errors
On Error GoTo DisplayErrorMsg

' Prints out the BOM# Word file
..Documents.Open Filename:="S:\XBS\Technical
Support\TechnicalSupport\Letter Maintenance\BOM\BOM - GISC\" & Target,
ReadOnly:=False
End With

WrdApp.Visible = True

' If a Target is printed the Error Message is ignored
GoTo Ignore

End If

' Ignores all if user selects vbNo
If intResponse = vbNo Then GoTo Ignore

'Ignores all other cells except BOM#
Else: GoTo Ignore

End If


DisplayErrorMsg:
MsgBox "The file " & Target & " could not be found.",
vbExclamation, "File Not Found"
Exit Sub


Ignore:
Exit Sub



End Sub
 
Top