Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Closing excel from a macro

I am currently opening excel from a java application. I use the excel object
(this workbook) to run several macros. The java application opens excel, so
every time excel is opened, some code must be run and then excel must be
close. The code I am trying to use is:

Private Sub Workbook_Open()
Macro1
tbmfile = "C:\excelfile.xls"
tbmxcelfile = "excelfile"
Windows(tbmxcelfile).Activate
ActiveWorkbook.Save
Application.Quit

If I step through this code it works fine and closes excel. But when I open
excelfile.xls from my documents, the macros are triggered to run, but excel
does not close. Why is that?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Closing excel from a macro

Your java application probably still has a reference to Excel which needs to
be released before excel can close.

I would also change

tbmxcelfile = "excelfile"

to
tbmxcelfile = "excelfile.xls"

if that is the name of the file.

--
Regards,
Tom Ogilvy

"maliaf" wrote in message
...
I am currently opening excel from a java application. I use the excel

object
(this workbook) to run several macros. The java application opens excel,

so
every time excel is opened, some code must be run and then excel must be
close. The code I am trying to use is:

Private Sub Workbook_Open()
Macro1
tbmfile = "C:\excelfile.xls"
tbmxcelfile = "excelfile"
Windows(tbmxcelfile).Activate
ActiveWorkbook.Save
Application.Quit

If I step through this code it works fine and closes excel. But when I

open
excelfile.xls from my documents, the macros are triggered to run, but

excel
does not close. Why is that?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Closing excel from a macro

Dear Tom

Thank you for the rapid response. The problem is not with the Java
application still maintaining a link. I ran a test for that; the java
application was not running and was closed. The excel sheet containing the
code to be launched on the open command was opened manually. I also
changed the file name as you have suggested and the problem still persists.
If I step through the code, the Application.Quit command works fine and excel
closes. But if I open excel, and the excelfile.xls then the code runs up
until the ActiveWorkbook.Save command and then does not quit. Why is this
happening?

I thank you for your help in advance.



"Tom Ogilvy" wrote:

Your java application probably still has a reference to Excel which needs to
be released before excel can close.

I would also change

tbmxcelfile = "excelfile"

to
tbmxcelfile = "excelfile.xls"

if that is the name of the file.

--
Regards,
Tom Ogilvy

"maliaf" wrote in message
...
I am currently opening excel from a java application. I use the excel

object
(this workbook) to run several macros. The java application opens excel,

so
every time excel is opened, some code must be run and then excel must be
close. The code I am trying to use is:

Private Sub Workbook_Open()
Macro1
tbmfile = "C:\excelfile.xls"
tbmxcelfile = "excelfile"
Windows(tbmxcelfile).Activate
ActiveWorkbook.Save
Application.Quit

If I step through this code it works fine and closes excel. But when I

open
excelfile.xls from my documents, the macros are triggered to run, but

excel
does not close. Why is that?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Closing excel from a macro

As you say, the code runs fine in one instance, thus there is little to be
said based on looking at the code you have provided. I gave you the most
likely cause and you said that is not a problem.

--
Regards,
Tom Ogilvy


"maliaf" wrote:

Dear Tom

Thank you for the rapid response. The problem is not with the Java
application still maintaining a link. I ran a test for that; the java
application was not running and was closed. The excel sheet containing the
code to be launched on the open command was opened manually. I also
changed the file name as you have suggested and the problem still persists.
If I step through the code, the Application.Quit command works fine and excel
closes. But if I open excel, and the excelfile.xls then the code runs up
until the ActiveWorkbook.Save command and then does not quit. Why is this
happening?

I thank you for your help in advance.



"Tom Ogilvy" wrote:

Your java application probably still has a reference to Excel which needs to
be released before excel can close.

I would also change

tbmxcelfile = "excelfile"

to
tbmxcelfile = "excelfile.xls"

if that is the name of the file.

--
Regards,
Tom Ogilvy

"maliaf" wrote in message
...
I am currently opening excel from a java application. I use the excel

object
(this workbook) to run several macros. The java application opens excel,

so
every time excel is opened, some code must be run and then excel must be
close. The code I am trying to use is:

Private Sub Workbook_Open()
Macro1
tbmfile = "C:\excelfile.xls"
tbmxcelfile = "excelfile"
Windows(tbmxcelfile).Activate
ActiveWorkbook.Save
Application.Quit

If I step through this code it works fine and closes excel. But when I

open
excelfile.xls from my documents, the macros are triggered to run, but

excel
does not close. Why is that?




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Closing excel from a macro

Thank you for the reply. I ran the excel file on a different machine. A
machine which does not have the software installed to run the java
application or the java files which call upon this excefile, so I am mistaken
in saying that there is no chance that a link could still exist? The same
problem persists. I know that this is annoying and I am sorry for bother you
again. I noticed another strange thing; when I open excel and the excel file
the first time the Application.Quit does not work; (a box comes up saying
code execution has been interuppted without me causing the break) even when I
press continue. This break occurs on the Application.Quit command. When i
then close this workbook (and not excel) and open it again the
Application.Quit command works. The things bothering me is why does the code
execution has been interuppted box pop up unprompted and why does the
Application.Quit command only work the second time round? What I would want
to happen is when excel is opened and then the exelfile is open, the macros
must run, the workbook must be save (both of these commands work) and then
excel must close (this does not work).

Your help is greatly appreciated.

Thanks


"Tom Ogilvy" wrote:

As you say, the code runs fine in one instance, thus there is little to be
said based on looking at the code you have provided. I gave you the most
likely cause and you said that is not a problem.

--
Regards,
Tom Ogilvy


"maliaf" wrote:

Dear Tom

Thank you for the rapid response. The problem is not with the Java
application still maintaining a link. I ran a test for that; the java
application was not running and was closed. The excel sheet containing the
code to be launched on the open command was opened manually. I also
changed the file name as you have suggested and the problem still persists.
If I step through the code, the Application.Quit command works fine and excel
closes. But if I open excel, and the excelfile.xls then the code runs up
until the ActiveWorkbook.Save command and then does not quit. Why is this
happening?

I thank you for your help in advance.



"Tom Ogilvy" wrote:

Your java application probably still has a reference to Excel which needs to
be released before excel can close.

I would also change

tbmxcelfile = "excelfile"

to
tbmxcelfile = "excelfile.xls"

if that is the name of the file.

--
Regards,
Tom Ogilvy

"maliaf" wrote in message
...
I am currently opening excel from a java application. I use the excel
object
(this workbook) to run several macros. The java application opens excel,
so
every time excel is opened, some code must be run and then excel must be
close. The code I am trying to use is:

Private Sub Workbook_Open()
Macro1
tbmfile = "C:\excelfile.xls"
tbmxcelfile = "excelfile"
Windows(tbmxcelfile).Activate
ActiveWorkbook.Save
Application.Quit

If I step through this code it works fine and closes excel. But when I
open
excelfile.xls from my documents, the macros are triggered to run, but
excel
does not close. Why is that?





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro Code for closing excel... Bonbon[_4_] Excel Programming 5 April 12th 06 12:57 PM
Prevent running macro upon closing Excel Deneb Excel Programming 2 February 2nd 05 06:07 PM
Closing excel with a macro TJexcel Excel Programming 1 December 8th 04 07:42 AM
Closing Excel from a Macro Jimmy Excel Programming 6 August 20th 04 02:25 AM
Closing Excel down with a macro? andycharger[_28_] Excel Programming 2 May 6th 04 04:18 PM


All times are GMT +1. The time now is 12:12 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"