DATA Step, Macro, Functions and more

Running VB from SAS EG

Reply
Contributor
Posts: 70

Running VB from SAS EG

[ Edited ]

Hi All - I am having a hard time making the VB script work from EG. We are migrating from PC SAS to SAS EG, but the below piece of code doesnt work. Any suggestions?

 

 

Below macro runs VBScript vbscript.vbs. PFA script. This vbscript reads ‘test.doc’ and creates vbscript.txt file.

 

%macro test;

filename vbscript pipe "cscript vbscript.vbs" console=min;

data _null_;

                infile vbscript ;

                input;

                stop;

run;

%mend test;

options mprint;

%test;

 

·         When we ran this code from BASE SAS 9.4, the file vbscript.txt is created successfully.

·         When we ran script ff44f002.vbs from command prompt, the file vbscript.txt is created successfully.

·         But when we ran this macro code from SAS Enterprise Guide, the file file vbscript.txt is not getting created. We getting below note in the log

Stderr output:

C:\Documents\vbscript.vbs(8, 1) Microsoft Word: This command is not available because

no document is open.

 

Content of vb script is as below.

 

dim objwd
dim mytest
set objwd = wscript.createobject("Word.Application")
objwd.visible=false
fname="C:\Documents\test.doc"
objWD.documents.open(fname),false, true,false
outname="C:\Documents\vbscript.txt"
objwd.activedocument.saveas(outname),5
objwd.documents.close
objwd.application.quit

 

Super User
Posts: 10,500

Re: Running VB from SAS EG

By any chance does your new EG environment involve a server? The file paths would all have to be something the server can use. This may mean moving some of your files to a shared network location or another approach that lets both you as user and the server read and write files to a location.

Contributor
Posts: 70

Re: Running VB from SAS EG

Yes, our new EG environment is connecting to a remote windows server. we are actually creating the file at a shared location, but still not able to exeucte the script.

Super User
Posts: 3,106

Re: Running VB from SAS EG

It looks like your VB script is trying to open an MS Word document. If EG is connecting to a remote Windows SAS server there is no console environment for Word to open in hence your script fails. I strongly suspect your script will only work with local SAS on your PC.

Contributor
Posts: 70

Re: Running VB from SAS EG

Sorry for the late response. Yes, EG is connecting to a remote server and I beleive that is the reason the script fails. Is there any other way to achieve this?

 

Please let me know.

PROC Star
Posts: 1,561

Re: Running VB from SAS EG

So you want MS WORD to open a .doc file and save it as a .txt file?

Is MS WORD installed on the server?

As @SASKiwi said I am unsure how/if WORD opens when no viewing port is available. Something that you mat want to test before proceeding.

Contributor
Posts: 70

Re: Running VB from SAS EG

Yes, MS Word is instaled on the server.

Super User
Posts: 3,106

Re: Running VB from SAS EG

What does your VB script do apart from opening MS Word? The bottom line is that MS Word is not designed to be opened remotely on a server. 

Contributor
Posts: 70

Re: Running VB from SAS EG

The script will try to open the word instance and copy the content to a text file.

PROC Star
Posts: 1,561

Re: Running VB from SAS EG

[ Edited ]

EG is very limiting in terms of what you control compared to SAS. One of the reasons is that everything now runs on a server.

Try starting MS word like this to see what happens. It should appear in the list of processes on the server.

 

filename TEST pipe '____path_to_office___\winword.exe';
data _null_; infile TEST; input; put _infile_; run;

 

The /x switch may help, even though we are not doing DDE here (untested). See

https://support.office.com/en-gb/article/Command-line-switches-for-Microsoft-Office-Word-2007-8be53d...

Contributor
Posts: 70

Re: Running VB from SAS EG

I see this in the log file. Also, I dont see an instance of word process opening on the server.

 

NOTE: The infile TEST is:

Unnamed Pipe Access Device,

PROCESS=C:\Program Files (x86)\Microsoft Office\Office14\winword.exe,

RECFM=V,LRECL=32767

 

PROC Star
Posts: 1,561

Re: Running VB from SAS EG

What's the data step log output? Have you tried the X switch?
Ask a Question
Discussion stats
  • 11 replies
  • 512 views
  • 0 likes
  • 4 in conversation