Loop through excel processes for a specific workbook

Vinhermes

Member
Joined
Aug 15, 2012
Messages
7
Programming Experience
Beginner
Dear All,

I have managed to isolate a specific workbook in amongst several workbooks in the same Excel instance but I now would like to do the same when several excel processes are running.

Here is the code below but unfortunately, it doesn't loop as expected in the excel instances. I am pretty sure this comes for the " For Each p As Process In pProcess":


Dim WorkbookOpen As Boolean = False
Dim Excel As Process() = Process.GetProcessesByName("EXCEL")
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
Dim ExcelApp As Excel.Application = Interaction.GetObject(, "Excel.Application")

If File.Exists(XLSFilename) Then

If Excel.Length > 0 Then

For Each p As Process In pProcess

For Each Workbook As Excel.Workbook In ExcelApp.Workbooks
If Workbook.FullName = XLSFilename Then

MsgBox("SUPER")
Exit For
End If
Next
Next
End If

Else
MessageBox.Show("Fichier non trouvable", "Attention", MessageBoxButtons.OK)
End If



Any help is more than welcome! Thank you by advance, Vincent
 
Back
Top