Results 1 to 6 of 6

Thread: completely quit the created object in VBA excel

  1. #1

    Thread Starter
    Registered User
    Join Date
    Aug 2022
    Posts
    4

    Unhappy completely quit the created object in VBA excel

    Hi there.,

    I'm doing a code for running Syntax of SPSS
    by creating SPSS object in VBA excel -> run SPSS Syntax -> close SPSS object -> run next SPSS Syntax
    so far, it can run the first Spss Syntax (*.sps file) very smoothly.

    But the code seems not working well. It didn't close(quit) completely SPSS object.
    and It can not run the second Spss'Syntax (the next *.sps file)

    Is there any idea for my case?
    How could completely close/quit/dispose SPSS created object?

    Any idea is appreciated
    Thank in advance.

    Code:
    Sub runspsssyntax()
    
    Dim i As Integer, link As String
    Dim SPSS As spsswin.Application
    
    For i = 0 To 40
    link = "C:\Users\" & i & ".sps"
    
    Set SPSS = GetObject(, "SPSS.Application")
    SPSS.ExecuteInsert FileName:=link, syntaxBatch:=True, errorStop:=False, cd:=True, Sync:=True
    
    SPSS.Quit
    Set SPSS = Nothing
    Next i
    
    End Sub

  2. #2

    Thread Starter
    Registered User
    Join Date
    Aug 2022
    Posts
    4

    Re: completely quit the created object in VBA excel

    Is there any idea for me, please?

    Thanks

  3. #3
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,443

    Re: completely quit the created object in VBA excel

    Why are you Creating and quitting inside the loop?
    Untested
    Code:
    Sub runspsssyntax()
    
    Dim i As Integer, link As String
    Dim SPSS As spsswin.Application
    Set SPSS = GetObject(, "SPSS.Application")
    
    For i = 0 To 40
    link = "C:\Users\" & i & ".sps"
    
    
    SPSS.ExecuteInsert FileName:=link, syntaxBatch:=True, errorStop:=False, cd:=True, Sync:=True
    
    
    Next i
    SPSS.Quit
    Set SPSS = Nothing
    End Sub
    What baffles me completely:
    You have those scripts in "c:\Users"????
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  4. #4
    Hyperactive Member
    Join Date
    Jan 2018
    Posts
    268

    Re: completely quit the created object in VBA excel

    I'm guessing you'd have better luck with IBM support than here.

  5. #5

    Thread Starter
    Registered User
    Join Date
    Aug 2022
    Posts
    4

    Re: completely quit the created object in VBA excel

    Quote Originally Posted by Zvoni View Post
    Why are you Creating and quitting inside the loop?
    Untested
    I think that VBA excel will call SPSS Object then
    run SPSS Syntax -> close SPSS object -> call new SPSS object -> run next SPSS Syntax -> so on...
    Because I already have SPSS syntaxes,

    normally I open SPSS application, open SPSS syntax, Ctrl + A that syntax, Ctrl + R to run that Syntax.
    SPSS application would give me what I want. THEN close SPSS. Perform steps over and over again.

    so far, I have 20 -> 100 syntaxes and more than, it really takes time to perform one by one by mormally.

    What baffles me completely:
    You have those scripts in "c:\Users"????
    the completely address will be: "C:\Users\admin\Desktop\gst regis\example001.sps"
    with example001.sps is model number 001

    Thanks

  6. #6

    Thread Starter
    Registered User
    Join Date
    Aug 2022
    Posts
    4

    Re: completely quit the created object in VBA excel

    is it possible if we use "Application.sendkeys" for VBA sendkeys to objects to Quit it-self?

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width