<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://customerfx.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Jason Buss&amp;#39; Blog : SalesLogix, scripting, Application Objects, How-To</title><link>http://customerfx.com/pages/customization/archive/tags/SalesLogix/scripting/Application+Objects/How-To/default.aspx</link><description>Tags: SalesLogix, scripting, Application Objects, How-To</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP2 (Build: 20611.960)</generator><item><title>Using the Excel Application Object with SalesLogix </title><link>http://customerfx.com/pages/customization/2009/02/19/using-the-excel-application-object-with-saleslogix.aspx</link><pubDate>Thu, 19 Feb 2009 14:16:00 GMT</pubDate><guid isPermaLink="false">e15581aa-2787-4c59-a940-524c09f5d256:40198</guid><dc:creator>Jason Buss</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://customerfx.com/pages/customization/rsscomments.aspx?PostID=40198</wfw:commentRss><comments>http://customerfx.com/pages/customization/2009/02/19/using-the-excel-application-object-with-saleslogix.aspx#comments</comments><description>&lt;p&gt;The Excel application object gives you the ability to programmatically create, modify and manipulate Excel spreadsheets.&amp;nbsp; Use that object with SalesLogix, and you have a powerful tool for exporting SLX data.&lt;/p&gt;&lt;p&gt;This post will outline the basics for creating and populating a new Excel spreadsheet, and will also provide an example of doing so with SalesLogix data. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;First of all, we need to instantiate the object:&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set xlApp = CreateObject(&amp;quot;Excel.Application&amp;quot;)&lt;/b&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;Afterwards, we need to create a new worksheet, and make the spreadsheet editable by the end user:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set xlWb = xlApp.Workbooks.Add&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Set xlWs = xlWb.Worksheets(&amp;quot;Sheet1&amp;quot;)&lt;br /&gt;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;These next lines make the spreadsheet visible and editable to the end user:&lt;b&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; xlApp.Visible = True&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; xlApp.UserControl = True&lt;/b&gt;
 &lt;br /&gt;&lt;/p&gt;&lt;p&gt;At this point, populating individual cells in the active worksheet is simple:&lt;/p&gt;&lt;p&gt;&lt;b&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xlWs.Cells(1, 1).Value = &amp;quot;Test&amp;quot;&lt;/b&gt;&lt;/p&gt;&lt;p&gt;A value of &amp;quot;Test&amp;quot; is put in position 1, 1 (or A1).&amp;nbsp; All you really need to do at this point is repeat that last line for whichever cells you want to populate.&amp;nbsp; As an example, here is code that will generate a list of Contacts for a specific account:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Dim objRS, iCount, xlApp, xlWb, xlWs&lt;/p&gt;&lt;p&gt;Set xlApp = CreateObject(&amp;quot;Excel.Application&amp;quot;)&amp;nbsp; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;Set xlWb = xlApp.Workbooks.Add&lt;br /&gt;Set xlWs = xlWb.Worksheets(&amp;quot;Contacts&amp;quot;) &lt;/p&gt;&lt;p&gt;xlApp.Visible = True&lt;br /&gt;xlApp.UserControl = True&amp;nbsp;
 &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;After setting up the Excel object, we are setting up a header row:&lt;/b&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;xlWs.Rows(cnt).Font.Bold = True&lt;br /&gt;xlWs.Cells(1, 1).Value = &amp;quot;First Name&amp;quot;&lt;br /&gt;xlWs.Cells(1, 2).Value = &amp;quot;Last Name&amp;quot;&lt;br /&gt;xlWs.Cells(1, 3).Value = &amp;quot;Title&amp;quot;&lt;br /&gt;xlWs.Cells(1, 4).Value = &amp;quot;Work Phone&amp;quot;&lt;br /&gt;xlWs.Cells(1, 5).Value = &amp;quot;Type&amp;quot;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Then we create a new recordset containing contact records, and loop through that recordset to populate the new spreadsheet.&lt;/b&gt; &lt;br /&gt;&lt;/p&gt;&lt;p&gt;Set objRS =Application.CreateObject(&amp;quot;ADODB.RecordSet&amp;quot;)&lt;/p&gt;&lt;p&gt;With objRS&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; .Open &amp;quot;select firstname, lastname, title, workphone, type from contact where
accountid = &amp;#39;&amp;quot; &amp;amp; Application.BasicFunctions.CurrentAccountID &amp;amp; &amp;quot;&amp;#39;&amp;quot;, Application.GetNewConnection&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; iCount = 2 &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; While not (.BOF or .EOF)&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xlWs.Cells(iCount, 1).Value = .Fields(&amp;quot;firstname&amp;quot;).Value&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xlWs.Cells(iCount, 2).Value = .Fields(&amp;quot;lastname&amp;quot;).Value&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xlWs.Cells(iCount, 3).Value = .Fields(&amp;quot;title&amp;quot;).Value&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xlWs.Cells(iCount, 4).Value = .Fields(&amp;quot;workphone&amp;quot;).Value&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; xlWs.Cells(iCount, 5).Value = .Fields(&amp;quot;type&amp;quot;).Value&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; iCount = iCount + 1 &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; .MoveNext&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; Wend &lt;/p&gt;&lt;p&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp; .Close &lt;br /&gt;&lt;/p&gt;&lt;p&gt;End With &lt;br /&gt;&lt;/p&gt;Set xlWs = Nothing&lt;br /&gt;&lt;p&gt;Set xlWb = Nothing&lt;br /&gt;Set xlApp = Nothing&lt;/p&gt;&lt;p&gt;Set objRS = Nothing &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;b&gt;That&amp;#39;s all there is to it!&lt;/b&gt;&lt;/p&gt;&lt;p&gt;There is quite a bit more to the Excel application object that I have not touched on here.&amp;nbsp; I would suggest reviewing available resources to see what other options are available to you.&amp;nbsp; A good place to start would be here:&amp;nbsp; &lt;a href="http://msdn.microsoft.com/en-us/library/aa213696%28office.11%29.aspx" title="http://msdn.microsoft.com/en-us/library/aa213696(office.11).aspx" target="_blank"&gt;http://msdn.microsoft.com/en-us/library/aa213696(office.11).aspx&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;Thanks for reading!&amp;nbsp; &lt;img src="http://customerfx.com/emoticons/emotion-1.gif" alt="Smile" /&gt;&lt;br /&gt;&lt;img src="http://customerfx.com/aggbug.aspx?PostID=40198" width="1" height="1"&gt;</description><category domain="http://customerfx.com/pages/customization/archive/tags/SalesLogix/default.aspx">SalesLogix</category><category domain="http://customerfx.com/pages/customization/archive/tags/Development/default.aspx">Development</category><category domain="http://customerfx.com/pages/customization/archive/tags/How-To/default.aspx">How-To</category><category domain="http://customerfx.com/pages/customization/archive/tags/ADO/default.aspx">ADO</category><category domain="http://customerfx.com/pages/customization/archive/tags/scripting/default.aspx">scripting</category><category domain="http://customerfx.com/pages/customization/archive/tags/Application+Objects/default.aspx">Application Objects</category><category domain="http://customerfx.com/pages/customization/archive/tags/Excel/default.aspx">Excel</category></item></channel></rss>