BookmarkSubscribeRSS Feed
KBACHU
Fluorite | Level 6

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

 

11 REPLIES 11
ballardw
Super User

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.

KBACHU
Fluorite | Level 6

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.

SASKiwi
PROC Star

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.

KBACHU
Fluorite | Level 6

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.

ChrisNZ
Tourmaline | Level 20

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.

KBACHU
Fluorite | Level 6

Yes, MS Word is instaled on the server.

SASKiwi
PROC Star

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. 

KBACHU
Fluorite | Level 6

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

ChrisNZ
Tourmaline | Level 20

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...

KBACHU
Fluorite | Level 6

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

 

ChrisNZ
Tourmaline | Level 20
What's the data step log output? Have you tried the X switch?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 11 replies
  • 2335 views
  • 0 likes
  • 4 in conversation