Date: Tue, 15 Mar 2011 10:02:04 +0100
Reply-To: la volta statistics <schmidhauser@lavolta.ch>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: la volta statistics <schmidhauser@lavolta.ch>
Subject: AW: transmitting parameter to Word
In-Reply-To: <439878.93372.qm@web110711.mail.gq1.yahoo.com>
Content-Type: multipart/alternative;
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: <mailto:schmidhauser@lavolta.ch> mailto:schmidhauser@lavolta.ch
Web: www.lavolta.ch
_____
Von: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] Im Auftrag von
Albert-Jan Roskam
Gesendet: Montag, 14. März 2011 20:38
An: SPSSX-L@LISTSERV.UGA.EDU
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 <schmidhauser@lavolta.ch>
To: SPSSX-L@LISTSERV.UGA.EDU
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: <mailto:schmidhauser@lavolta.ch> mailto:schmidhauser@lavolta.ch
Web: www.lavolta.ch
[text/html]