|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Excel already runnig, how to update with VBrunning, and if it is, then do something with the active workbook. I can see if Excel is running: Private Sub GetAllExcelApps() Dim AllExeclProcesses() As Process Dim OneExcelProcess As Process Dim OneExcelApp As Excel.Application ' get all open instances of excel AllExeclProcesses = Process.GetProcessesByName("EXCEL") ' Iterate through the process array. For Each OneExcelProcess In AllExeclProcesses ' do something Next End Sub But how do I convert OneExcelProcess into OneExcelApp? I can create an Excel Application instance: Private Sub MyExcelProcess() Dim MyExcelApp As Excel.Application = New Excel.Application ' do somthing MyExcelApp.Quit() MyExcelApp = Nothing End Sub But I do not want a new Excel application. I want to be able to do something only is Excel is already running. Thanks I'm not sure if it will work, but maybe try using a direct cast statement or
something similar: Dim OneExcelApp as Excel.Application OneExcelApp = DirectCast(OneExcelProcess, Excel.Application) Show quoteHide quote "easoftw***@gmail.com" wrote: > I would like to be able to use VB 2003 .NET to check if Excel is > running, and if it is, then do something with the active workbook. > > I can see if Excel is running: > > Private Sub GetAllExcelApps() > > Dim AllExeclProcesses() As Process > Dim OneExcelProcess As Process > Dim OneExcelApp As Excel.Application > > ' get all open instances of excel > AllExeclProcesses = Process.GetProcessesByName("EXCEL") > > ' Iterate through the process array. > For Each OneExcelProcess In AllExeclProcesses > ' do something > Next > End Sub > > But how do I convert OneExcelProcess into OneExcelApp? I can create an > Excel Application instance: > > Private Sub MyExcelProcess() > Dim MyExcelApp As Excel.Application = New Excel.Application > > ' do somthing > > MyExcelApp.Quit() > MyExcelApp = Nothing > End Sub > > But I do not want a new Excel application. I want to be able to do > something only is Excel is already running. > > Thanks > > Okay I tried DirectCast and it didn't work. I also tried CType and that
didn't work either. If you absolutley have to perform something with the Excel file that is already open, maybe you should use VBA? A temporary workaround might be to terminate the running Excel process and then force the user to reselect the file in an OpenFileDialog and then create a new instance of the workbook that way. Although that is rather lame. Show quoteHide quote "John" wrote: > I'm not sure if it will work, but maybe try using a direct cast statement or > something similar: > > Dim OneExcelApp as Excel.Application > OneExcelApp = DirectCast(OneExcelProcess, Excel.Application) > > > > > > "easoftw***@gmail.com" wrote: > > > I would like to be able to use VB 2003 .NET to check if Excel is > > running, and if it is, then do something with the active workbook. > > > > I can see if Excel is running: > > > > Private Sub GetAllExcelApps() > > > > Dim AllExeclProcesses() As Process > > Dim OneExcelProcess As Process > > Dim OneExcelApp As Excel.Application > > > > ' get all open instances of excel > > AllExeclProcesses = Process.GetProcessesByName("EXCEL") > > > > ' Iterate through the process array. > > For Each OneExcelProcess In AllExeclProcesses > > ' do something > > Next > > End Sub > > > > But how do I convert OneExcelProcess into OneExcelApp? I can create an > > Excel Application instance: > > > > Private Sub MyExcelProcess() > > Dim MyExcelApp As Excel.Application = New Excel.Application > > > > ' do somthing > > > > MyExcelApp.Quit() > > MyExcelApp = Nothing > > End Sub > > > > But I do not want a new Excel application. I want to be able to do > > something only is Excel is already running. > > > > Thanks > > > >
Unique an array of strings
Co-existing ASP.NET 1.1 and 2.0??? Accessing Structure Members Communication between threads Transactions through Remoting Function doesn't return a value on all code paths Simple xpath question *** Using DataReaders to populate combo boxes - please help!!! *** Monitor Software Installation Changes surpress newline on Enter press |
|||||||||||||||||||||||