More help on closing Excel.Application

S

Snedker

Okay - it seems I haven't explained myself properly, so:

Would someone show me a VBA example of:

1.
Open "C:\mywork.xls" using the Excel.Appliction object

2.
Enter "Hello World" into cell A1

3.
Releasing connections to the open xls-file, but leaving it open for
further work.

4.
The code should be able to be re-run an infinite number of times, each
time opening "C:\mywork.xls" in a new instance of Excel.


Help greatly appreciated! Thx in advance.

/Snedker
 
R

Rob van Gelder

Sub testit()
Dim app As Application, wkb As Workbook, i As Long

For i = 1 To 3
Set app = New Application
app.Visible = True
Set wkb = app.Workbooks.Open("C:\mywork.xls")
wkb.Worksheets(1).Cells(1, 1) = "Hello World"
Set wkb = Nothing
Set app = Nothing
Next
End Sub

Keep in mind that the second time you open mywork.xls it will be read-only
(unless it's a shared workbook)
 
H

Henry

Snedker,

How much memory has your system got?
It must be infinite, if you're hoping to open an infinite number of
instances of Excel!!

HTH
Henry
 
T

Tushar Mehta

You may want to check

Office Application Automation
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/modcore/html/deconAutomatingOtherOfficeApplications.asp

and

Creation of Object Variables to Automate Another Office Application
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/modcore/html/deconCreatingObjectVariableToAutomateAnotherOfficeAppli
cation.asp

While there check out other related topics shown in the left hand
navigation bar.

--
Regards,

Tushar Mehta, MS MVP -- Excel
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
Top