transmitting parameter to Word

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

transmitting parameter to Word

la volta statistics

Hi all

 

I would like to open a Word document with SPSS 18, transmit a parameter to Word, so that the transmitted parameter is used in an AutoOpen code.

I was able to do that with SPSS 15 with the following Codes (Syntax (1), script (2)  and Word VBA (3) ):

 

(1) SPSS 15  syntax Code:

*********************

 

SCRIPT file= 'C:\CreateWord.SBS'

          (myStrParameter).

 

(2) CreateWord.SBS:

*****************.

Option Explicit

 

Dim objWord As Object

Dim objWordApp As Object

Dim objDocument As Object

 

Sub Main

Dim strParameters       As String

strParameters = objSpssApp.ScriptParameter(0)  'GetParameter

Set objWord = CreateObject("Word.Application")

myPath = "C:\Temp\Test.doc"

 

Set objDocument = objWord.Documents.Open(myPath )

objWord.Visible = True

 

End sub

 

(3) Word VBA Code:

**************

 

Sub AutoOpen()

Dim objSpssApp          As spsswin.Application

Dim strScriptParam      As String

 

Set objSpssApp = GetObject(, "SPSS.Application")

 

strScriptParam = objSpssApp.ScriptParameter(0)

 

MsgBox strScriptParam

 

End sub

 

 

I would like to do that now with Python, but was not able to figure out how to transmit the parameter.

 

BEGIN PROGRAM.

import win32com.client

app = win32com.client.Dispatch('Word.Application')

doc = app.Documents.Open('C:\Temp\Test.doc')

#app.Quit()

END PROGRAM.

 

Additionally, I seem to have a problem to reference SPSS 18 in the VBA code since I have SPSS 15 and SPSS 18 installed at the same computer.

 

Can somebody help me?

 

Thanks in advance

Christian

 

 

 

 

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
[hidden email] 
Web: www.lavolta.ch

 

Reply | Threaded
Open this post in threaded view
|

Re: transmitting parameter to Word

Jon K Peck
The original Python version of the SCRIPT command did not provide for parameter passing.  That was added later.  I think that this ability is in V18, but if not, you can use the SCRIPTEX extension command from the SPSS Community (www.ibm.com/developerworks/spssdevcentral).  The documentation for that command explains how to provide and retrieve the parameter(s).

You should be able to use Basic with either 15 or 18, but note that the application name changed in V16.  In that version and later it is as below.
Set objSpssApp = GetObject(, "SPSS.Application16")

Jon Peck
Senior Software Engineer, IBM
[hidden email]
312-651-3435




From:        la volta statistics <[hidden email]>
To:        [hidden email]
Date:        03/14/2011 11:00 AM
Subject:        [SPSSX-L] transmitting parameter to Word
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi all
 
I would like to open a Word document with SPSS 18, transmit a parameter to Word, so that the transmitted parameter is used in an AutoOpen code.
I was able to do that with SPSS 15 with the following Codes (Syntax (1), script (2)  and Word VBA (3) ):
 
(1) SPSS 15  syntax Code:
*********************
 
SCRIPT file= 'C:\CreateWord.SBS'
          (myStrParameter).
 
(2) CreateWord.SBS:
*****************.
Option Explicit
 
Dim objWord As Object
Dim objWordApp As Object
Dim objDocument As Object
 
Sub Main
Dim strParameters       As String
strParameters = objSpssApp.ScriptParameter(0)  'GetParameter
Set objWord = CreateObject("Word.Application")
myPath = "C:\Temp\Test.doc"
 
Set objDocument = objWord.Documents.Open(myPath )
objWord.Visible = True
 
End sub
 
(3) Word VBA Code:
**************
 
Sub AutoOpen()
Dim objSpssApp          As spsswin.Application
Dim strScriptParam      As String
 
Set objSpssApp = GetObject(, "SPSS.Application")
 
strScriptParam = objSpssApp.ScriptParameter(0)
 
MsgBox strScriptParam
 
End sub
 
 
I would like to do that now with Python, but was not able to figure out how to transmit the parameter.
 
BEGIN PROGRAM.
import win32com.client
app = win32com.client.Dispatch('Word.Application')
doc = app.Documents.Open('C:\Temp\Test.doc')
#app.Quit()
END PROGRAM.
 
Additionally, I seem to have a problem to reference SPSS 18 in the VBA code since I have SPSS 15 and SPSS 18 installed at the same computer.
 
Can somebody help me?
 
Thanks in advance
Christian
 
 
 
 
 
**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
mailto:schmidhauser@...
Web:
www.lavolta.ch
 
Reply | Threaded
Open this post in threaded view
|

Re: transmitting parameter to Word

Albert-Jan Roskam
In reply to this post by la volta statistics
Hi,

What do you mean with 'AutoOpen code'?

Did you also consider using something like this? Might be easier than COM calls.

import subprocess
path = r"C:\Program Files\Microsoft Office\OFFICE11\winword.exe"
try:
  subprocess.check_call(path + " d:/temp/output.htm")
except subprocess.CalledProcessError:
  print "Oops"


    check_call(*popenargs, **kwargs)
        Run command with arguments.  Wait for command to complete.  If
        the exit code was zero then return, otherwise raise
        CalledProcessError.  The CalledProcessError object will have the
        return code in the returncode attribute.
       
        The arguments are the same as for the Popen constructor.  Example:
       
        check_call(["ls", "-l"])
 
Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



From: la volta statistics <[hidden email]>
To: [hidden email]
Sent: Mon, March 14, 2011 6:05:40 PM
Subject: [SPSSX-L] transmitting parameter to Word

Hi all

 

I would like to open a Word document with SPSS 18, transmit a parameter to Word, so that the transmitted parameter is used in an AutoOpen code.

I was able to do that with SPSS 15 with the following Codes (Syntax (1), script (2)  and Word VBA (3) ):

 

(1) SPSS 15  syntax Code:

*********************

 

SCRIPT file= 'C:\CreateWord.SBS'

          (myStrParameter).

 

(2) CreateWord.SBS:

*****************.

Option Explicit

 

Dim objWord As Object

Dim objWordApp As Object

Dim objDocument As Object

 

Sub Main

Dim strParameters       As String

strParameters = objSpssApp.ScriptParameter(0)  'GetParameter

Set objWord = CreateObject("Word.Application")

myPath = "C:\Temp\Test.doc"

 

Set objDocument = objWord.Documents.Open(myPath )

objWord.Visible = True

 

End sub

 

(3) Word VBA Code:

**************

 

Sub AutoOpen()

Dim objSpssApp          As spsswin.Application

Dim strScriptParam      As String

 

Set objSpssApp = GetObject(, "SPSS.Application")

 

strScriptParam = objSpssApp.ScriptParameter(0)

 

MsgBox strScriptParam

 

End sub

 

 

I would like to do that now with Python, but was not able to figure out how to transmit the parameter.

 

BEGIN PROGRAM.

import win32com.client

app = win32com.client.Dispatch('Word.Application')

doc = app.Documents.Open('C:\Temp\Test.doc')

#app.Quit()

END PROGRAM.

 

Additionally, I seem to have a problem to reference SPSS 18 in the VBA code since I have SPSS 15 and SPSS 18 installed at the same computer.

 

Can somebody help me?

 

Thanks in advance

Christian

 

 

 

 

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
[hidden email] 
Web: www.lavolta.ch

 


Reply | Threaded
Open this post in threaded view
|

AW: transmitting parameter to Word

la volta statistics

Hi Albert-Jan

 

Thanks fort he code.

AutoOpen() is a code that gets executed when the Word document is opened. I found it useful to run some code in Word with a parameter received from SPSS. For example:

 

Sub AutoOpen()

 

Dim objSpssApp          As spsswin.Application

Dim strScriptParam      As String

Dim mReturn             As Integer

Set objSpssApp = GetObject(, "SPSS.Application")

 

strScriptParam = objSpssApp.ScriptParameter(0)

 

mReturn = insertTables(strScriptParam)

 

End sub

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
[hidden email] 
Web: www.lavolta.ch


Von: SPSSX(r) Discussion [mailto:[hidden email]] Im Auftrag von Albert-Jan Roskam
Gesendet: Montag, 14. März 2011 20:38
An: [hidden email]
Betreff: Re: transmitting parameter to Word

 

Hi,

What do you mean with 'AutoOpen code'?

Did you also consider using something like this? Might be easier than COM calls.

import subprocess
path = r"C:\Program Files\Microsoft Office\OFFICE11\winword.exe"
try:
  subprocess.check_call(path + " d:/temp/output.htm")
except subprocess.CalledProcessError:
  print "Oops"


    check_call(*popenargs, **kwargs)
        Run command with arguments.  Wait for command to complete.  If
        the exit code was zero then return, otherwise raise
        CalledProcessError.  The CalledProcessError object will have the
        return code in the returncode attribute.
       
        The arguments are the same as for the Popen constructor.  Example:
       
        check_call(["ls", "-l"])

 

Cheers!!
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

 

 


From: la volta statistics <[hidden email]>
To: [hidden email]
Sent: Mon, March 14, 2011 6:05:40 PM
Subject: [SPSSX-L] transmitting parameter to Word

Hi all

 

I would like to open a Word document with SPSS 18, transmit a parameter to Word, so that the transmitted parameter is used in an AutoOpen code.

I was able to do that with SPSS 15 with the following Codes (Syntax (1), script (2)  and Word VBA (3) ):

 

(1) SPSS 15  syntax Code:

*********************

 

SCRIPT file= 'C:\CreateWord.SBS'

          (myStrParameter).

 

(2) CreateWord.SBS:

*****************.

Option Explicit

 

Dim objWord As Object

Dim objWordApp As Object

Dim objDocument As Object

 

Sub Main

Dim strParameters       As String

strParameters = objSpssApp.ScriptParameter(0)  'GetParameter

Set objWord = CreateObject("Word.Application")

myPath = "C:\Temp\Test.doc"

 

Set objDocument = objWord.Documents.Open(myPath )

objWord.Visible = True

 

End sub

 

(3) Word VBA Code:

**************

 

Sub AutoOpen()

Dim objSpssApp          As spsswin.Application

Dim strScriptParam      As String

 

Set objSpssApp = GetObject(, "SPSS.Application")

 

strScriptParam = objSpssApp.ScriptParameter(0)

 

MsgBox strScriptParam

 

End sub

 

 

I would like to do that now with Python, but was not able to figure out how to transmit the parameter.

 

BEGIN PROGRAM.

import win32com.client

app = win32com.client.Dispatch('Word.Application')

doc = app.Documents.Open('C:\Temp\Test.doc')

#app.Quit()

END PROGRAM.

 

Additionally, I seem to have a problem to reference SPSS 18 in the VBA code since I have SPSS 15 and SPSS 18 installed at the same computer.

 

Can somebody help me?

 

Thanks in advance

Christian

 

 

 

 

 

**********************************
la volta statistics

Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
CH-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email:
[hidden email] 
Web: www.lavolta.ch