LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (September 2000, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 28 Sep 2000 09:22:42 GMT
Reply-To:   autretx@MY-DEJA.COM
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   autretx@MY-DEJA.COM
Organization:   Deja.com - Before you buy.
Subject:   Re: writing to a different worksheet in an excel file than the first one

You can do that in DDE:

French example:

filename CMD dde'excel|system';

data _NULL_; file CMD; put '[SEL.CLASSEUR("Feuil5")]'; put '[INSERER.CLASSEUR(1)]'; run;

For guessing the english equivalent, try to get Excel 5.0 and make a macro with language Excel 4.0 the code is DDE code.

You can have a look to VBA commands

SAS examples: The following example uses SCL code to populate a Microsoft Excel spreadsheet with data from a SAS data set: Load an instance of the OLE Automation class and invoke Microsoft Excel as the new object. Set the object's Visible attribute to true so you can see the automation.

LAUNCHXL: hostcl = loadclass('sashelp.fsp.hauto'); call send (hostcl, '_NEW_', excelobj, 0, 'Excel.Application.5'); call send (excelobj,'_SET_PROPERTY_','Visible','True'); return;

Get the identifier for the current Workbooks property and add a worksheet to it. Then get the identifier for the new worksheet.

CREATEWS: call send (excelobj,'_GET_PROPERTY_','Workbooks', wbsobj); call send (wbsobj, '_DO_', 'Add' ); call send (excelobj,'_GET_PROPERTY_','ActiveSheet', wsobj );

Open a SAS data set.

dsid=open('sasuser.class','i'); call set(dsid); rc=fetch(dsid); nvar=attrn(dsid, 'NVARS'); nobs=attrn(dsid, 'NOBS');

Traverse the data set and populate the cells of the Excel worksheet with its data, row by row.

do col=1 to nvar; call send (wsobj, '_COMPUTE_', 'Cells',1,col,retcell); var=varname(dsid,col); call send (retcell, '_SET_PROPERTY_', 'Value' ,var); end; do while (rc ne -1); do row = 1 to nobs; do col = 1 to nvar; r=row+1; call send (wsobj, '_COMPUTE_', 'Cells', r ,col, retcell); if vartype(dsid,col) eq 'N' then var=getvarn(dsid,col); else var=getvarc(dsid,col); call send (retcell,'_SET_PROPERTY_', 'Value' ,var); end; rc=fetch(dsid); end; end; return;

Close the worksheet and end the Excel session.

QUITXL: call send (excelobj,'_GET_PROPERTY_', 'ActiveWorkbook', awbobj ); call send (awbobj, '_DO_', 'Close', 'False' ); call send (excelobj,'_DO_', 'Quit' ); call send (excelobj,'_TERM_' ); return;

As you can see from this example, automating an application object requires some knowledge of the object's properties and methods. To help you decide which SCL commands to use for an Excel automation object, you can use the Macro Recorder in Excel to perform the task you want to automate and then look at the Visual Basic code that is generated. It is then relatively simple to map the Visual Basic code to comparable SCL statements and functions. Here are some excerpts of Visual Basic code with their SCL equivalents:

Visual Basic code OLE Automation in SCL Launch Excel and make it visibleSet excelobj = CreateObject ("Excel.Application.5") excelobj.Visible = True

hostcl = loadclass('sashelp.fsp.hauto'); call send ( hostcl, '_NEW_', excelobj, 0, 'Excel.Application.5'); call send (excelobj,'_SET_PROPERTY_', 'Visible','True');

Create a new worksheetDim wbsobj, wsobj As Object Set wbsobj = excelobj.Workbooks wbsobj.Add Set wsobj = excelobj.ActiveSheet call send(excelobj,'_GET_PROPERTY_', 'Workbooks', wbsobj); call send(wbsobj, '_DO_', 'Add'); call send(excelobj,'_GET_PROPERTY_', 'ActiveSheet', wsobj );

Set the value of a cellwsobj.Cells(row + 1, col).Value = var r=row+1; call send(wsobj,'_COMPUTE_', 'Cells', r, col, retcell); call send(retcell,'_SET_PROPERTY_', 'Value' ,var); Close the Excel application objectexcelobj.ActiveWorkbook.Close ("False") excelobj.Quit call send(excelobj,'_GET_PROPERTY_', 'ActiveWorkbook', awbobj); call send(awbobj, '_DO_', 'Close',

Copyright (c) 1996, SAS Institute Inc., Cary, NC 27513-2414 USA. All rights reserved.

In article <8qur50$ghhrs$1@ID-25433.news.cis.dfn.de>, "Sebastian" <einer.einer@gmx.net> wrote: > Hi, > > i need to export data to an excel-file, how can i write into the second, > third, ... worksheet in the file? I did not find any useful option... > > Regards > Sebastian > >

Sent via Deja.com http://www.deja.com/ Before you buy.


Back to: Top of message | Previous page | Main SAS-L page