Hi Guys,
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
At first I misunderstood the problem and it is more complicated than I thought.
Set myXL = CreateObject("Excel.Application")
Creates new processes (I thought it didn't), but still strange thing is happening. I use OLE to store Excel files in SQL Server databse.
This is the function that bounds excel file to a form:
Public Function OpenExcelObjFrame() As BoundObjectFrame
Dim myXL As Object
Set myXL = CreateObject("Excel.Application") '#1
Set gTempWorkbook = myXL.Workbooks.Add
myXL.Visible = True '#2
DoCmd.OpenForm "Excel_OBJ"
Forms("Excel_OBJ").Visible = False
Forms("Excel_OBJ").RecordSource = "SELECT Excel_File FROM Excel_File_Obj;"
Set OpenExcelObjFrame = Forms("Excel_OBJ").Excel_File
End Function
The context:
Dim tExcelObjFrame As BoundObjectFrame
Set tExcelObjFrame = OpenExcelObjFrame()
tExcelObjFrame.Verb = acOLEVerbOpen
tExcelObjFrame.Action = acOLEActivate '#3
ad 1 2nd process excel.exe starts
ad 2 Added this line to check what is happening to the 2nd process
ad 3 OLE bounds the file to existing excel instance, the 2nd process is killed here :/
So the problem is:
Why the tExcelObjFrame.Action = acOLEActivate kills the 2nd process
How to force Object Frame to activate excel file in the 2nd process
EDIT
I've found partial explanation here (with no clear solution):
http://www.xtremevbtalk.com/showthread.php?t=292170
- If no instance of Excel is running, OLE creates an instance of Excel when you access the object, either directly or through programmation.
- If an instance of Excel is already running, then this is the instance that is used by the OLE object.
The problem is that OLE object chooses wrong excel instance. Question is if there is a way to point OLE to a specific instance.
Same problem described here (no solution given):