Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro Code for closing excel... | Excel Programming | |||
Prevent running macro upon closing Excel | Excel Programming | |||
Closing excel with a macro | Excel Programming | |||
Closing Excel from a Macro | Excel Programming | |||
Closing Excel down with a macro? | Excel Programming |