I am using XLOpen in a macro, but now have a situation where the desired file is already open for other reasons. In this case, MS opens a second, read-only copy. Since my macro is wanting to write to the open file, this does not work.
Is there a way to either use XLOpen with a file that is already open, or is there a way to get the handle for an already-open Excel file so that I can pass that handle to XLSetCell?
Thank you,
Ken
Get handle for excel file that is already open?
Moderators: Dorian (MJT support), JRL
Re: Get handle for excel file that is already open?
Now sure if you can connect with the open file with the MS functions, but you can always use VBS to connect and work with it, simple example below (when there is one instance of excel open, possible with one or more open workbooks).
Code: Select all
VBSTART
Sub toXL(file,sheet,cell,val)
Set objExcel = GetObject( ,"Excel.Application")
objExcel.workbooks(file).sheets(sheet).range(cell)=val
End Sub
VBEND
Let>file=test.xlsx
Let>sheet=Sheet1
Let>cell=a2
Let>val=123
VBRun>toXL,file,sheet,cell,val
VBRun>toXL,test.xlsx,Sheet2,b33,28