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.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1169 views
  • 0 likes
  • 3 in conversation