Date: Mon, 25 Aug 2008 11:32:12 -0500
Reply-To: "./ ADD NAME=Data _null_," <iebupdte@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "./ ADD NAME=Data _null_," <iebupdte@GMAIL.COM>
Subject: Re: SAS issuing print command to Word
In-Reply-To: <200808232023.m7NAkVt2010212@malibu.cc.uga.edu>
Content-Type: text/plain; charset=ISO-8859-1
Hi Art,
Your print command is correct, argument 9 is the pages argument,
except I could not get it to work without also specifying argument 3
wdPrintRangeOfPages which I guessed at the value 4.
Here is a script I found from "The Scripting Guys"
http://tinyurl.com/6s5xrc that I modified to print page one of each
file. This script did not mention argument 3 either Then I put it all
into a data step so I can be called from SAS. It uses a FILEREF to
point to the directory of WORD files.
data _null_ / pgm=work.PrintPage1;
length path script filevar command $256;
path = pathname('FT77F001');
script = catx('\',pathname('WORK'),'PRINTPAGE1.vbs');
filevar = script;
/* write the script */
file dummy1 filevar=filevar;
put 'Const ' path=$quote258.;
put 'Const wdPrintRangeOfPages = "4"';
put 'Set objWord = CreateObject("Word.Application")';
put 'objWord.Visible = True';
put 'Set objDoc = objWord.Documents.Add()';
put 'strComputer = "."';
put 'Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")';
put 'Set FileList = objWMIService.ExecQuery _';
put +3 '("ASSOCIATORS OF {Win32_Directory.Name=''" & path &"''} Where " _';
put +6 '& "ResultClass = CIM_DataFile")';
put 'For Each objFile In FileList';
put +3 'If objFile.Extension = "doc" Then';
put +6 'WScript.Echo objFile.name';
put +6 'objWord.PrintOut ,,wdPrintRangeOfPages,,,,,,"1",,,,objFile.Name';
put +6 'End If';
put +3 'Next';
put 'objWord.Quit';
/* close the script file by opening another, not used */
filevar = catx('\',pathname('WORK'),'DUMMY.vbs');
file dummy1 filevar=filevar;
/* look at the script, not necessary but may be useful */
infile dummy2 filevar=script end=eof;
do until(eof);
input;
putlog _infile_;
end;
/* call the script */
command = catx(' ','cscript',quote(strip(script)));
infile dummy3 pipe filevar=command end=eof;
do until(eof);
input;
putlog _infile_;
end;
stop;
run;
filename FT77F001 "C:\Documents and Settings\&sysuserid\My Documents";
filename FT77F001 list;
data pgm=work.PrintPage1;
run;
filename FT77F001 clear;
On 8/23/08, Arthur Tabachneck <art297@netscape.net> wrote:
> Joakim,
>
> As Joe and Howard pointed out, you can probably do what you want with
> either dde or SAS/AF.
>
> I, personally, find developing vbs code (outside of SAS), a lot more
> parsimonious, easier to explain and easier to change.
>
> However, I'm still not sure if my latest version will do what you want, as
> it still prints all pages on my printer. Since that could just be my
> outdated home printer driver, I'd suggest at least trying it on some
> relatively small files.
>
> The "1-1" part of the "put @1 'objWord.PrintOut ,,,,,,,,"1-1",,,,"'@;"
> statement, below, according to Microsoft should print only the range of
> pages 1 thru 1.
>
> Art
> -----
> *identify the desired files;
> FileName GetDir Pipe "dir c:\art\*.doc /d /B /s" ;
>
> * build vbs program;
> data _null_;
> file "s:\art\getdocs.vbs" LRECL =300;
> infile GetDir lrecl=300 truncover;
> input @1 fullpath $255. @;
> put @1 'Set objWord = CreateObject("Word.Application")';
> put @1 'objWord.Visible = True';
> put @1 'Set objDoc = objWord.Documents.Add()';
> put @1 'objWord.PrintOut ,,,,,,,,"1-1",,,,"'@;
> put fullpath @;
> put '"';
> put @1 'objWord.Quit';
> run;
>
> *run vbs code;
> option noxsync;
> data _null_;
> x "c:\art\getdocs.vbs";
> run;
>
> Art
> --------------
> >Joakim,
> >
> >The following is NOT the full solution, but it may be enough to prompt
> >someone from the list (who is better at vbs than I am) to (1) add the
> >missing fromto command (which does exist in word script) and (2) show how
> >the concept can be simplified.
> >
> >In any case, you can build and run vbs script from SAS. Take, for
> >example, the following:
> >
> >*identify the desired files;
> >FileName GetDir Pipe "dir c:\art\*.doc /d /B /s" ;
> >
> >* build vbs program;
> >data _null_;
> > file "s:\art\getdocs.vbs" LRECL =300;
> > infile GetDir lrecl=300 truncover;
> > input @1 fullpath $255. @;
> > put @1 'Set objWord = CreateObject("Word.Application")';
> > put @1 'Set objDoc = objWord.Documents.Open("'@;
> > put fullpath @;
> > put '")';
> > put @1 'objDoc.PrintOut()';
> > put @1 'objWord.Quit';
> >run;
> >
> >*run vbs code;
> >option noxsync;
> >data _null_;
> > x "c:\art\getdocs.vbs";
> >run;
> >
> >The first part uses a pipe to identify the fullpaths of the files you want
> >to print.
> >
> >The second part builds a vbs program that prints the files.
> >
> >The third part actually runs the vbs code.
> >
> >I think the code can be simplified quite a bit and, of course, someone has
> >to suggest what it needed to limit the code to only print the first page
> >from each document.
> >
> >HTH,
> >Art
> >---------
> >On Fri, 22 Aug 2008 21:00:18 +0200, Joakim Englund
> ><joakim.englund@GMAIL.COM> wrote:
> >
> >>Dear professionals,
> >>
> >>Is there a way using SAS code to command Word to print the first page of
> >all
> >>word files in a directory?
> >>
> >>Kind Regards,
> >>Joakim
>
|