BookmarkSubscribeRSS Feed
angeliquec
Quartz | Level 8

Hi, X Commands are disabled in our SAS server, and won't be enabled. With that, I'd like to know how can I execute a vb script I made for the consolidation of these multiple excel sheets. I know it's possible to fix the sequence using ODS tagsets, but since there is a lot of ongoing program development and revision, I prefer to perform the consolidation at the end of my SAS program. 

 

VB Script sample as below:

 

Function Cpypaste (xlfile)
Dim xlfile_nm
xlfile_nm = xlfile
'MsgBox xlfile_nm
Set CopyFromWbk = objExcel.Workbooks.Open(FolderPath & xlfile_nm & ".xlsx")
'Worksheet.Name = xlfile_nm
Set ShToCopy = CopyFromWbk.Sheets(1)
ShToCopy.Copy CopyToWbk.Sheets(CopyToWbk.Sheets.Count)
CopyFromWbk.Close


End Function

3 REPLIES 3
Oligolas
Barite | Level 11

Hi,

 

maybe something like this:

%macro consolidateXlsxSheets(FolderPath=,xlfile=,vbsFileName=);

   %let saveOpt=%sysfunc(getOption(QUOTELENMAX));
   options noquotelenmax;
   data _null_;
      file "&vbsFileName";
      put " Dim objExcel ";
      put " Dim FSO";
      put " Dim objWorkBook";
      put " Set objExcel = CreateObject(""Excel.Application"")";
      put " Set FSO = CreateObject(""Scripting.FileSystemObject"")";

      put " objExcel.DisplayAlerts = False";
    
      put " Dim xlfile_nm";
      put " xlfile_nm = &xlfile.";
      put " 'MsgBox xlfile_nm";
      put " Set CopyFromWbk = objExcel.Workbooks.Open(&FolderPath. & xlfile_nm & "".xlsx"")";
      put " 'Worksheet.Name = xlfile_nm";
      put " Set ShToCopy = CopyFromWbk.Sheets(1)";
      put " ShToCopy.Copy CopyToWbk.Sheets(CopyToWbk.Sheets.Count)";
      put " CopyFromWbk.Close";

      put " objExcel.DisplayAlerts = True";
      put " objExcel.Quit";
      put " Set objExcel = Nothing";
      put " FSO.DeleteFile(""&vbsFileName""), DeleteReadOnly";
      put " Set FSO = Nothing"; 
   run;
   data _null_;
      call system("""&vbsFileName"""); * 3 quotes in order to work with names containing spaces;
   run;
   options &saveOpt.;
%mend consolidateXlsxSheets;
%consolidateXlsxSheets(FolderPath=,xlfile=,vbsFileName=c:\xyz.vbs);
________________________

- Cheers -

angeliquec
Quartz | Level 8

Thanks! It's a working alternative to the X statement, but I'm still getting a Shell Escape not valid error. 

ballardw
Super User

@angeliquec wrote:

Hi, X Commands are disabled in our SAS server, and won't be enabled. With that, I'd like to know how can I execute a vb script I made for the consolidation of these multiple excel sheets. I know it's possible to fix the sequence using ODS tagsets, but since there is a lot of ongoing program development and revision, I prefer to perform the consolidation at the end of my SAS program. 

 

VB Script sample as below:

 

Function Cpypaste (xlfile)
Dim xlfile_nm
xlfile_nm = xlfile
'MsgBox xlfile_nm
Set CopyFromWbk = objExcel.Workbooks.Open(FolderPath & xlfile_nm & ".xlsx")
'Worksheet.Name = xlfile_nm
Set ShToCopy = CopyFromWbk.Sheets(1)
ShToCopy.Copy CopyToWbk.Sheets(CopyToWbk.Sheets.Count)
CopyFromWbk.Close


End Function


If you are generating that output to multiple sheets from SAS then likely you could just change how the output is generated from SAS.

If using ODS  tagsets.excelxp or ods excel then the SHEET_INTERVAL option controls how sheets are generated and likely use of NONE would send all of the output to a single sheet so the post processing is not needed.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 681 views
  • 0 likes
  • 3 in conversation