More help on closing Excel.Application

  • Thread starter Thread starter Snedker
  • Start date Start date
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
 
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)
 
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
 
On Fri, 26 Dec 2003 22:07:35 -0000, "Henry" <[email protected]>
wrote:

Well, you shouldn't take it literally :-)

My VB-app will open the workbook and enter data automatically. They
should be able to return to the VB-app push a button and a new
instance of the workbook will be opened.

The workbook is initially read-only, so they're supposed to save to a
new filename anyway.

"Several times" would be a more appropiate choice of words, rather
than "infinite".

Regards
/Snedker
 
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
 
Back
Top