![]() |
Home Email me SEARCH |
Adeleida
Alan Bell
Alan Lepofsky
Andy Donaldson
Arne Nielsen
Ben Langhinrichs
Ben Poole
Bill Buchan
BlogSphere
Brian Benz
Bruce Elgort
Captain Oblivious
Carl Tyler
Chris Byrne
Chris Coates
Chris Linfoot
Chris Miller
Chris Toohey
Chris Whisonant
Christian Brandlehner
CodeStore
Craig Schumann
Curt Stone
Damien Katz
Declan Lynch
Devin Olson
DomBlog.de
domlike.net
Duffbert
Ed Brill
Fabian Nirman
Ferdy Christant
Gayle Elgort
Grant Bingham
Gregg Eldred
Hassan Voyeau
Heini Schwammerl
Ian Irving
Jack Dausman
Jens-Christian Fischer
Jerry Carter
Johan Känngård
John Mill
John Roling
John Vaughan
Just Enough Governance
Justin Knol
Kathy Sierra
Keith Strickland
Ken Yee
Kevin Pettitt
Kurt Higley
Lance Spellman
Laurette Rynne
Mac Guidera
Matt and Jess
Matt White
Mikkel Heisterberg
Mrs Elsmore
Nathan Freeman
News4Notes
nsftools
OpenNTF Blog
Paul Mooney
PhotoTechno Reflections
Ray Bilyk
Richard Schwartz
Richard Spense
Rob Novak
Rob Wunderlich
Rocky Oliver
Roy Holder
Scott Good
Sean Burgess
Simon Peek
Squirrelly Notes
Stan Rogers
Stephan H. Wissel
Steve Castledine
Susan Bulloch
Taking Notes
Tim Rynne
Tim Tripcony
Tom's Rant
Turtle
Vince Schuurman
Volker Weber
Warren Elsmore
I've posted some code before for exporting from Notes to Excel. Now I'm posting a more complete routine, a bit more robust, with many added comments. I get asked on a semi-regular basis for code - or explanation of the "how" - for getting Notes and Excel to talk to each other. Well, given that one is running on top of Windows, Notes and Excel are just 2 of many applications that can communicate with each other using COM and OLE. So here is the export2Excel routine. This sample code is written as an agent that would run from within your personal Name and Address Book, and will export some of the fields from the Contact documents. Now I won't have to hunt around for an example the next time I'm asked -- or the next time I need to code one of these routines :-) (also be sure to check out the Notes to Excel Reporter free download at Steve Castledine's ProjectDX site).
I've tried to document this code fairly well (just remember, this is a freebie, so no complaints allowed!). But what may not be apparent is how to come up with the code to do the formatting of the Excel file after the data is exported. The answer is that I simply tweaked some code that Excel created for me. Here's how: The first step in using LotusScript from Notes to automate an Excel function, is to let Excel create some of the code for you. From the menu bar within Excel, click Tools > Macro > Record New Macro. You'll need to provide a name for the macro. Then go ahead and do whatever formatting or other tasks you want to automate, just like you normally would. When done, click the small blue icon to stop the recording (the icon will be displayed in a small window on the Excel sheet when you start recording). Now it's time to have a look at the code that Excel generated. Click Tools > Macro > Macros. Select the macro that you just recorded, and click Edit. What appears in a new window is the VBA code (Visual Basic code) that Excel created for you while recording the macro. Very cool. Much of this code can be pasted directly into your LotusScript code, but you will definitely need to provide values for any Excel constants that appear in the code. So how do you find those values? Well one easy way is to create a small macro in Excel and let the macro tell you the needed value. From the Excel sheet, click Tools > Macro > Macros, click the Create button to create a new macro, type in a name for your macro, and click Edit. Now, let's say you want to find the value that you need to provide to LotusScript for the Excel constant named 'xlPaperLetter'. In the new Sub module that Excel created for you, type in this single line of code: MsgBox "The value of xlPaperLetter is <" & xlPaperLetter & ">" Now go back to the Excel window that has the worksheet open, and click Tools > Macro > Macros, select the new macro you just created, and click Run. A message box will pop up displaying this message: The value of xlPaperLetter is <1> Well, that tells you that if you want to use the 'xlPaperLetter' Excel constant from within your LotusScript code, you will need to create an Integer variable (or constant) with a value of numeric 1. For example, you could add this line to the Declarations of your LotusScript routine: Const xlPaperLetter = 1 If you follow this procedure to discover the value of other Excel constants, you will soon realize that there are many constants with the same value. Now if you really want to save some time, you can download a Notes database listing the MS-Office constants (thanks to John Coolidge and Duffbert.) |
1. Posted by Wolfgang Flamme - website09/09/2007 08:43 PM
Joe, good job, nice introduction. And the code is a good OOP candidate, too. With respect to using VBA constants in LS, this might be helpful:
http://www.sns1.de/partner/flamme/wflamme.nsf/Shortcut/DumpTypeLibInfo1
Placed in an action or button this LS code will dump all VBA constants of the indicated application into a ready-to-use LSS file - documentation comments included (if available).
In addition it's not limited to MS Office but can dump whatever the VBA object browser has access to. Maybe one day I'm going to write a routine to strip declarations not used in the LS but nevertheless I found this very useful.
Yours,
Wolfgang
Simple Powerpoint Archiver/Analyzer
http://www.sns1.de/partner/flamme/wflamme.nsf/Shortcut/PowerPoint
2. Posted by Shep Peskoff09/09/2007 08:43 PM
Excellent stuff. Need further help. Am transferring L/N data to EXISTING spreadsheet. Works ok, but need to specify 'disable macros' to avoid popups during the process. Is there a parameter available to be applied during the accessing of the file? Thanks in advance.
3. Posted by Joe Litton - website09/09/2007 08:43 PM
Offhand, I don't know if there's a parameter that will turn off macros when opening the spreadsheet. If you *always* get the popup, you could use a little WinAPI code to send a keystroke to kill the popup (Enter or 'Y" or whatever). I've got a blurb about the WinAPI in LotusScript at http://joelitton.net/A559B2/home.nsf/plinks/JLIN-5M92NT ...If that doesn't work, shoot me an email and I'll see if I can find a more elegent programmatic solution. Cheers.












I've posted some code before for exporting from Notes to Excel. Now I'm posting a more complete routine, a bit more robust, with many added comments. I get asked on a semi-regular basis for code - or explanation of the "how" - for getting Notes and Excel to talk to each other. Well, given that one is running on top of Windows, Notes and Excel are just 2 of many applications that can communicate with each other using COM and OLE. So here is the