-
Never used this, but I have had trouble with multiple instances so nice to learn something new.
This seems to delete only the Word created instance, by defining it using the Excel File name
[VBA]
Option Explicit
Public appXL As Excel.Application
Public xlFile As Excel.Workbook
Sub test()
Dim FName As String
FName = "md001"
Set appXL = CreateObject("Excel.Application")
Set xlFile = appXL.Workbooks.Open _
(FileName:="C:\Temp\" & FName & ".xls")
appXL.Visible = True
xlFile.Worksheets("Sheet1").Range("A2").Select
Range("a65536").End(xlUp).Offset(1, 0).Select
ActiveCell.Select
If ActiveCell = "" Then
ActiveCell.Value = "MD"
End If
ActiveWorkbook.Save
'appXL.Visible = True
xlFile.Close True
Set xlFile = Nothing
appXL.Quit
Set appXL = Nothing
Call DOSDelete(FName)
End Sub
Sub DOSDelete(ExcelName As String)
Dim objFSO As Object
Dim objDOSFile As Object
Dim objShell As Object
Dim DOSCommands As String
Dim strCommand As String
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
DOSCommands = "TASKKILL EXCEL.EXE-" & ExcelName
Set objDOSFile = objFSO.CreateTextFile("DOSCommands.bat", 1)
objDOSFile.Write DOSCommands
objDOSFile.Close
strCommand = "cmd /c DOSCommands.bat "
objShell.Run strCommand, 0, True
Set objFSO = Nothing
Set objShell = Nothing
End Sub
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules