Thanks for quick response Shawn, Because the grid is very wide, I would not know which portions to print. The user already is very familiar with Excel's Preview, and chop and print features. Thus, I am not creating an Excel file (ie not Saving to file). I am just opening excel and formatting the data inti it.. I am then leaving it open, for the user to do what he pleases. .( I do provide the ability for the user to configure my grid, and save variations as 'Favorites', but he still may be sending wide grids to Excel. )
I had seen an example that created a file and closed everything. Since I am not creating a file (and Excel is open for who knows how long), should I be setting my objects to nothing ? Regards, Rob, [EMAIL PROTECTED] PS I will follow the advice regarding splitting up the functionality. ----- Original Message ----- From: "Shawn K. Hall" <[EMAIL PROTECTED]> To: <[email protected]> Sent: Thursday, February 10, 2005 9:44 PM Subject: RE: [vbhelp] Re: MSFlexGrid Hi Rob, > User has Excel, and in fact was quoting how great > it was at printing, when asking me to provide grid > printing. I provide formatting during the automation, > so that it looks much like my lovely SGrid-2 > configuration. That makes a difference. It's hard to generate quality reports from scratch in VB. > > Show us how you clean up when you close a document. > > I'm not cleaning up. > It was not an oversight, but rather uncertainty as > to the impact of setting objects to nothing, whilst > user is viewing the data in Excel. I had to 'invent' > it, and get it to the user quickly, so I dared not > risk having code that might effect the running Excel. I looked at the sample code (thanks) and it's simple and complete - but too self-contained. What I would do is split the main function into several routines. One routine for generating the actual Excel file from your data, one for formatting it, and a third to open it and/or print it. Something like: Sub ExportToExcel(sOutputFilename, bFormatIt) ' create objects ' do stuff if bformatit then FormatExcelDoc end if ' CLEAN UP - DESTROYING OBJECTS!!! End Sub Sub FormatExcelDoc() ' do the actual formatting if requested End Sub Sub PrintExcelDoc(sOutputFilename) ' ShellExecute the file - avoiding internal object ' instantiation liabilities ShellExec sOutputFilename, "print" End Sub Sub OpenExcelDoc(sOutputFilename) ' ShellExecute the file - avoiding internal object ' instantiation liabilities ShellExec sOutputFilename, "open" End Sub ShellExecute is the api call used to instantiate objects based on the verb under the HKCR section of the registry. As long as Excel is the default handler for these two verbs it will work fine. Here's a wrapper for the vaporcode above: '// ======================================================== Option Explicit '[Declares] Private Declare Function ShellExecute _ Lib "shell32.dll" _ Alias "ShellExecuteA" ( _ ByVal hwnd As Long, _ ByVal lpOperation As String, _ ByVal lpFile As String, _ ByVal lpParameters As String, _ ByVal lpDirectory As String, _ ByVal nShowCmd As Long) _ As Long '[Code] '********************************************************* ' Inputs : ByVal sFile$ = File to open ' : sVerb("open") = Verb to use ' Returns : Long = Result of ShellEx call ' Description : Opens files/urls with their associated app ' Samples : ShellExec "c:\stuff\myfile.xls", "print" ' : ShellExec "http://ReliableAnswers.com/" '********************************************************* Function ShellExec&(ByVal sFile$, Optional sVerb$ = "open") ShellExec = ShellExecute(0&, sVerb, sFile, "", "", 1&) End Function '// ======================================================== > If there is mild uncertainty regarding the versions > of Excel that users may be using it, should I use > early or late binding ? Actually, unless there is **absolute** certainty to the version of any components/apps your application uses, use late binding. Regards, Shawn K. Hall http://12PointDesign.com/ http://ReliableAnswers.com/ '// ======================================================== At a Sacramento PC Users Group meeting, a company was demonstrating its latest speech-recognition software. A representative from the company was just about ready to start the demonstration and asked everyone in the room to quiet down. Just then someone in the back of the room yelled,"Format C: Return." Someone else chimed in: "Yes, Return." Unfortunately, the software worked. '// ======================================================= Rules : http://ReliableAnswers.com/List/Rules.asp Home : http://groups.yahoo.com/group/vbHelp/ ======================================================= Post : [email protected] Join : [EMAIL PROTECTED] Leave : [EMAIL PROTECTED] '// ======================================================= Yahoo! Groups Links -- No virus found in this incoming message. Checked by AVG Anti-Virus. Version: 7.0.298 / Virus Database: 265.8.6 - Release Date: 7/02/2005 ---------- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.298 / Virus Database: 265.8.6 - Release Date: 7/02/2005 [Non-text portions of this message have been removed] '// ======================================================= Rules : http://ReliableAnswers.com/List/Rules.asp Home : http://groups.yahoo.com/group/vbHelp/ ======================================================= Post : [email protected] Join : [EMAIL PROTECTED] Leave : [EMAIL PROTECTED] '// ======================================================= Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/vbhelp/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
