Archive for November 2007

Beware the Indian Army

4-Hour Work Week
The 4-Hour Work Week

From page 115 of The 4-Hour Work Week:

Honey has completed her first project for me: research on the person Esquire has chosen as the Sexiest Woman Alive. I’ve been assigned to write a profile of this woman, and I really don’t want to have to slog through all the heavy-breathing fan websites about her. When I open Honey’s file, I have this reaction: America is f*cked. There are charts. There are section headers. There is a well-organized breakdown of her pets, measurements, and favorite foods (e.g. swordfish). If all Bangalorians are like Honey, I pity Americans about to graduate college. They’re up against a hungry, polite, Excel-proficient Indian army.

The Decline of VBA

In a previous post, I threw out a little quip about VBA going away. Based on some of the comments, I should clarify that remark.

First, I have no special or inside knowledge. Microsoft has said publicly that VBA will stay in Office for the foreseeable future and I believe that is true.

A few nits to pick: I doubt they really look past the next version, however, so the foreseeable future is really just a few years. Also, “staying in Office”, to quote myself, can mean a lot of things. XLM macros are still in Excel, but would you consider that macro language alive or dead?

Let me be more specific about my prediction. Remember this is pure speculation. I predict by version 15 (two versions from 2007) that changes to the UI will not be updated in the object model that Excel exposes to VBA. When they add embedded YouTube videos in Excel cells, you won’t be able to modify them programmatically. Further, I predict that VSTO, or whatever that evolves into, will be the “official” method for automating Office applications. The code will be separate from the Office document and will be “managed” (in quotes because I’m not 100% sure what that means). All of your VBA code will still run. It will still live in your documents and you will still be able to add, modify, and delete VBA code just as you do now. The adding of code will be limited to legacy features (remember no updates to the OM), but that will cover about 99% of what’s in Excel and 99.9% of what you want to use (with one notable exception). The last pain in your ass will be that spreadsheets will be, by default, unable to run “unmanaged” code. Your users will have to go into the Virtual Security Kiosk to enable running VBA code. Did I mention that this was speculation.

So that doesn’t mean that VBA is dead-dead, just dying. I will still write VBA code for myself and others. I will still encourage anyone to learn VBA if their goal is to automate Office applications. There’s really nothing wrong with learning VBA. Learning any language will be useful. I learned BASIC then Pascal in my formative years. I remember exactly nothing about Pascal but it probably helped me in some way and it certainly didn’t hinder any future learning. However, if a 13-year-old kid says he wants to be a coder, there’s probably a better path than one that goes through VBA.

Don’t stop writing macros or reading Excel blogs because I said VBA is dead.

What evidence do I have for these predictions? None, it’s all speculation. Haven’t you been paying attention? Well, there are a few things, I guess. First, there’s no VBA in the Mac version of Office. I’m not sure if that happened in the last version or will happen in the next version, but it’s official. Maybe MS is simply getting out of the Apple business and it’s no real reflection on VBA. Or maybe VBA isn’t an asset with a future so the cost of porting it to Apple’s new OS isn’t worth the cost.

Microsoft is a tool of governments. Governments threaten to use open source products and Microsoft comes out with XML. Why on earth would anyone store a spreadsheet as a text file? The only reason is that because some influential customer says that they need an open format. The people who make those decisions aren’t the people who use VBA.

Microsoft is a tool of big business. IT managers hate Excel and Access. They want all of the programming needs of the company to flow through the IT department. They don’t want accountants writing VBA code that could delete a bunch of files. On the other hand, accountants don’t want to wait three months to get a bug fixed in their invoicing program. Is MS pandering to the IT manager or the accountant?

There’s this minor little change to the UI in Excel 2007 called the Ribbon. Maybe you’ve heard of it. There’s no Ribbon object in the Excel or Office object models. Oh sure, there’s plenty of great reasons why the Ribbon isn’t there. But it’s not. And next time it will be something else. Then something else. Then the OM is static.

I called MS a tool twice and a panderer once. Those are meant to be a little derogatory because I’m neither a government or a big business. But, honestly, who can blame them for trying to meet the needs of their largest customers? I don’t. It’s exactly what I would be doing if I were in their shoes. And I’m not overly concerned about the VSTO future of Office automation. I separate my code and data now, so it’s not that big of a change for me. If they put VBA syntax in the CLR (DLR?), it would be a non-issue for me.

Finally, I should address those that say “Microsoft isn’t stupid. They won’t alienate such a large customer base by relegating VBA to the attic.” Won’t they?

VBA Help Stats

via Tony’s Microsoft Access Blog

Let’s Talk about Office VBA Help

Access help gets the most page views, followed by VB Core and Excel. Then there’s a huge drop off for apps like Word and Outlook. Interesting.

VBA for Beginners

As I’ve been whittling away at my Bloglines backlog, I read some interesting comments at Philip Greenspun’s blog. Phil asks,

Best Computer Language for a 13-year-old Beginner?

His first thought was Visual Basic. There wasn’t a lot of support for VB in the comments. There are some seemingly cool beginner programs out there like Scratch, Alice, and Hackety-hack, all of which I’ve noted for when I’m ready to handcuff my son to a computer and force him to learn how to program. And there was, of course, the obligatory suggestions of Perl, Python, PHP and MySQL, HTML and CSS, C++, and C#. C++ for a beginner?

I began to think about how VBA would fit into the mix. I’m not sure I could, in good conscience, teach a 13-year-old VBA. I predict VBA will be gone in the not-too-distant future and it wouldn’t do the kid justice to teach him a dying language. However, I think there are some properties of VBA that are useful to a beginning programmer.

The most obvious of those helpful properties, at least in Excel, is the macro recorder. Most VBA programmers who can remember their formative years will agree that the macro recorder is very helpful when it comes to learning the syntax and the object model.

VBA also offers a kind-of self-contained environment in which to work. It’s certainly possible to destroy your operating system from VBA, but a beginner will likely be changing properties and calling methods of objects like Workbook, Worksheet, and Range. If things get out of hand, close the workbook and start fresh.

The immediate feedback of VBA is nice too. You can run just-written code and see the effects right away in the UI. You don’t have to compile to an exe or anything like that. Speaking of immediate, there’s also the Immediate Window for trying out code.

There’s a lot of positive aspects of VBA when it comes to beginners. If a 13-year-old showed a genuine interest in VBA, I wouldn’t turn him away. But I don’t think I’d suggest it to someone interested in “programming”. Your thoughts?

In other news, I downloaded Instant Rails the other days and went through the cookbook tutorial. Very cool. I bought a book and decided that my cold-Nebraska-winter project is to learn Ruby.

“Animate” a 2007 RibbonX image

The quotes around the first word should alert the reader that this is not about actually animating a ribbon image but rather about simulating the effect.

The end effect of the experimentation described in this proof-of-concept note is the alternating image for the Custom Italic button
dde-animate-1.gif
and

A few days ago I was developing a 2007 interface for some add-in. After trying out a few icons, it became apparent that an animated GIF (called AGIF below) would be the most effective way to convey some of the features of the add-in. I vaguely remembered some discussion at the last MVP summit that RibbonX did not support AGIFs. But, hoping I was wrong, my first attempt was to just that. I put one together (nothing fancy, just two images that alternated ad infinitum), created an empty workbook, saved it as a XLSM file, and opened it in the Office 2007 Custom UI Editor.

In the editor, I used one of the sample templates (Excel – A Custom Tab) to create a test ribbon. For one of the buttons (id=”customButton1?), I set the image attribute to the name of the AGIF, inserted the image file into the XLSM, saved the file, and opened it in Excel. Unfortunately, there was nothing wrong with my recollection. The ribbon did not animate the AGIF.

So, I figured that was that…until a day or so later when I was boarding a plane at some unearthly hour. Just as I got to my seat, I couldn’t help but think, “Duh! If you must, use code to swap the images!” While it wouldn’t be true animation (no custom transition effects) and it would require VBA code running on a timed basis, it might work in the right circumstances.

So, thoughts of sleep forgotten, I pulled out the laptop as soon as we climbed above 10,000 feet. Opening the XLSM file, I used one of the other buttons to specify the attribute getImage=”getImage”

<button id=”customButton1? label=”ConBold” size=”large” onaction=”conBoldSub” image=”animate”/>
<button id=”customButton2? label=”ConItalic” size=”large” onaction=”conItalicSub” getimage=”getImage”/>

Of course, now I had to write some code to provide RibbonX with the image at the appropriate time and also invalidate the control after so-many-seconds. The invalidation would cause RibbonX to ask for the image again, and this time the code would provide a different image.

The code below contains three logical segments.

The first initializes the myRibbon variable.

The second provides RibbonX with the image of choice. Since I had two images, named animate-1.gif and animate-2.gif, the code alternates between the two.

The third section is the timing controller. For the test, I used a 5 second delay with the application’s OnTime method. So, every 5 seconds the code invalidates the CustomButton2 control, which causes RibbonX to call the getImage procedure, which, in turn, returns the next image in the rotating sequence.

Option&nbsp;Explicit
Dim&nbsp;myRibbon&nbsp;As&nbsp;IRibbonUI
Dim&nbsp;LastNbr&nbsp;As&nbsp;Integer,&nbsp;NextTime&nbsp;As&nbsp;Date
‘Callback&nbsp;for&nbsp;customUI.onLoad
Sub&nbsp;RibbonLoaded(ribbon&nbsp;As&nbsp;IRibbonUI)
&nbsp;&nbsp;&nbsp;&nbsp;Set&nbsp;myRibbon&nbsp;=&nbsp;ribbon
&nbsp;&nbsp;&nbsp;&nbsp;FiveSecsAnimate
&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;Sub
‘Callback&nbsp;for&nbsp;customButton2&nbsp;getImage
Sub&nbsp;getImage(control&nbsp;As&nbsp;IRibbonControl,&nbsp;ByRef&nbsp;returnedVal)
&nbsp;&nbsp;&nbsp;&nbsp;If&nbsp;LastNbr&nbsp;=&nbsp;0&nbsp;Then&nbsp;LastNbr&nbsp;=&nbsp;1&nbsp;Else&nbsp;LastNbr&nbsp;=&nbsp;LastNbr&nbsp;Mod&nbsp;2&nbsp;+&nbsp;1
&nbsp;&nbsp;&nbsp;&nbsp;Set&nbsp;returnedVal&nbsp;=&nbsp;LoadPicture(&nbsp;_
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ThisWorkbook.Path&nbsp;&&nbsp;Application.PathSeparator&nbsp;&&nbsp;”animate-”&nbsp;&&nbsp;LastNbr&nbsp;&&nbsp;”.gif”)
&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;Sub
Sub&nbsp;FiveSecsAnimate()
&nbsp;&nbsp;&nbsp;&nbsp;myRibbon.InvalidateControl&nbsp;”customButton2″
&nbsp;&nbsp;&nbsp;&nbsp;NextTime&nbsp;=&nbsp;Now&nbsp;+&nbsp;TimeValue(“0:0:5″)
&nbsp;&nbsp;&nbsp;&nbsp;Application.OnTime&nbsp;NextTime,&nbsp;”FiveSecsAnimate”
&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;Sub
Sub&nbsp;stopAnimation()
&nbsp;&nbsp;&nbsp;&nbsp;Application.OnTime&nbsp;NextTime,&nbsp;”FiveSecsAnimate”,&nbsp;,&nbsp;False
&nbsp;&nbsp;&nbsp;&nbsp;End&nbsp;Sub

For the test I used images in the same directory as the workbook.

In conclusion, ideally the images should be in the workbook itself. The code would then refer to those images. But, I don’t know enough about how to refer to images in an Office2007 file or how to get LoadPicture to work with those images. While the best solution would be for Ribbon/RibbonX to support animated GIFs, the above is an alternative for those who cannot wait for Microsoft to get around to it.

Gallimaufry

My new measure of how busy I am is how many unread blogs I have.

Yep, I’m swamped.

Part of the reason I’m swamped is because I took a long weekend last weekend. I went to Austin, TX for golf and a football game. I thought my beloved Cornhuskers would be losing so badly at half time that I could head back to the bar, but that wasn’t the case. They actually played well until the fourth quarter. Then they lost. Defensive Coordinator Kevin Cosgrove just can’t figure out that zone read option play.

When I returned home, my wife said she saw me on TV. If you were watching ABC at 2:48:15PM CDT, and you live in the correct region, you saw me too. I can’t get video off of my DVR, so I tried to take a photo of my TV. You can see it on flickr. I’m on the right. Starting from the left, it goes black shirt, white shirt, guy clapping with hands in front of face, then me wearing a red cap, dark glasses and looking to my right. Ah fame.

In Austin, I played golf at Wolfdancer. It’s a resort course, which means it’s a tough looking course that’s maintained in such a way that guests score well. I scored 84. They require a forecaddy – someone who tells you where to hit and then goes and finds your ball for you. We suspect that our forecaddy was foot-wedging some of our shots while we weren’t looking. If there really is a resort/forecaddy conspiracy then I say “kudos”. It worked on me, because I had a great time.

Last night was Halloween. Some people were putting their business cards in my son’s treat bag. I’m sure they took a marketing course at the community college or read Guerilla Marketing and are quite proud of themselves. I read the cards. You can be sure I won’t be buying from them even if I’m in their market. Some parts of our lives can be advertising free.

My cell phone has been ringing off the hook from the number 800-835-4431. Normally, I simply ignore telemarketers and they go away. This number was calling me three times a day. I googled it and discovered that I’m not the only one. This morning I finally answered it. It was Real Software, makers of RealBasic the VB6 replacement. They want me to pay $750 to go to their conference. I downloaded RealBasic a couple of years ago, but I never used it. Now they’re calling my cell phone to sell me stuff? Three times a day? While I’m registered on the National Do Not Call list, I really doubt that helps since I have “prior dealings” with this company. I no longer have nice things to say about them.