04-09-2021
01:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-09-2021
01:25 AM
it is possible to check if an file is alway open ?
I have an code da get some data form the model , copy an templete Excel fil , and then open it
My problem is that If i run the code without close the excel the Excel file have the same name as the part numer the code will fail.. that I want it to do is to check if the file is open , and if it is close it before copy the templete and open it again.
is there a way to do this ?
04-11-2021
09:59 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
04-11-2021
09:59 AM
Hello
You can try following
Add in the Header of your rule
AddReference "Microsoft.Office.Interop.Excel.dll"
Imports Microsoft.Office.Interop
Imports System.Runtime.InteropServices
In your rule add
Dim objApp As Excel.Application= TryCast(Marshal.GetActiveObject("Excel.Application"), Excel.Application)
If objApp IsNot Nothing Then
Dim objBooks As Excel.Workbooks
objBooks = objApp.Workbooks
Dim objBook As Excel._Workbook
For Each objBook In objBooks
If objBook.Name= "Document-Name_With-Extension-Without_Path" Then
'If objBook.FullName= "DocumentName_With-FullPath-and-Extension" Then 'alternative, if document name alone is not specific enough
objBook.Close
Exit For
End If
Next
End If
R. Krieg
RKW Solutions
www.rkw-solutions.com