Avatar billede xenoxsis Nybegynder
04. april 2008 - 10:50 Der er 5 kommentarer og
1 løsning

Checke om Excel Objectet kører

Hej,

Jeg har lavet et nyt Excel application objekt:

Dim objXL as New Excel.Application

Jeg skal arbejde med det her object lige indtil at min form bliver lukket. Så on FORM_CLOSE skal jeg have den til at kontrollere om objektet findes.

Jeg har prøvet:
objXL = Nothing og objXL is Nothing
og
objXL is Empty

Hvordan kan jeg få objektet til at blive lukket hvis det kører?
Avatar billede terry Ekspert
04. april 2008 - 11:44 #1
To close the object use
objXL.Close

And as long as you have error handling in place then you wont have a problem if teh object has been closed earlier.


Or you could use


On Error Resume Next
objXL.Close
Avatar billede xenoxsis Nybegynder
04. april 2008 - 16:03 #2
Well the thing is, that I have this button that runs through an Excel sheet, to get info and list it in a combobox.
When users presses a button, I need to get more info from Excel, so I dont wanna close excel when I added the stuff in the combobox, so to ensure that the program was only closed when I KNOW that I am done with the Excel sheet.

So I got this idea to close it when my form closes. But the only way I can do objXL.quit is when objXL exists (which is logically correct enough). So I need to check if ObjXL is not Nothing before I do: objXL.quit
Avatar billede terry Ekspert
04. april 2008 - 17:48 #3
If objXL Is Nothing Then
Avatar billede xenoxsis Nybegynder
09. april 2008 - 08:35 #4
Well I tried that - it doesnt work. I get a Run-time error '424': Object Required
Avatar billede xenoxsis Nybegynder
09. april 2008 - 09:20 #5
I got it...The problem was that I was dimentioning the objXL varible in a button key-press procedure. And it is therefore not dimentioned in other procedures. What I did was make a global objXL variable. And that fixed the problem.

But it was still your solution that did it Terry, and thus you get points. Thank you...
Avatar billede terry Ekspert
09. april 2008 - 13:29 #6
Yes if your using it globally then it has to be declared as a global variable

Thanks
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Dyk ned i databasernes verden på et af vores praksisnære Access-kurser

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester