ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Closing a word file? (https://www.excelbanter.com/excel-programming/287572-closing-word-file.html)

pgoodale[_5_]

Closing a word file?
 
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


Igno
Exit Sub



End Sub


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 01:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com