Wednesday, 27 January 2010

Excel VBA macros fail with merged cells

If you use a VBA macro to read or set the contents of a merged cell in Excel it appears to fail. The code I used for a non-merged cell was

    appExcel.ActiveSheet.Range("A35").select
    sContent = appExcel.Selection.Text

Reading the value for a merged cell returns a null pointer for each of the cells that are merged, where you might expect the top left cell at least to return the value Excel shows if you click in the merged cell. The code below reads the value correctly:

    Set objRange = appExcel.ActiveSheet.Range("A35").MergeArea
    sContent = objRange.Cells(1, 1)

Thanks to Antonio Bayah for the initial tip that led me to this.

Monday, 25 January 2010

Your Vista computer starts from hibernation overnight

So. You work on your laptop all evening, then hibernate it. When you come down stairs in the morning it has turned itself on and is sitting waiting for you to log in. If you're lucky it is on mains power, if not it is about to run out of battery. I've also heard of people finding their laptop waking up in its case and getting rather hot.

The problem is Windows Automatic Update. If you accept the default setting of install updates automatically at 3am it wakes up at 3am to do just that. Microsoft claim it will only do this on mains power and it will hibernate again afterwards. Experience suggests it may do it on battery power and may not turn off.

I suspect the problem is restarting after update. For a while MS managed to make most updates install without a restart but now most require one (more about this here). I assume that when the laptop powers up after the restart it has forgotten it is supposed to go back to sleep. Anyway, change the automatic update settings to download updates automatically and notify you but don't install. The added benefit is that you can avoid updates you don't want, like new versions of Internet Explorer and nagware like Windows Genuine Advantage. I also don't generally install updates till Windows Secrets has passed them as not likely to break your software.

How to fix a laptop computer - step one

Picked this up from a Toshiba tech support call centre. The rep was really apologetic that he didn't know what was wrong, so went to basic procedures. The first one fixed the problem. and the same technique has since fixed many laptop problems. Its a simple cold boot, but cold booting a laptop isn't quite as easy as a desktop.

Start by shutting down. Then remove all sources of power, i.e. unplug the charger and remove the battery. Then hold the power button down for a while. I'd give it 20-30 seconds. Then replace the battery and charger and restart.

The last step with the power button discharges the power supply capacitors which otherwise keep a small amount of power on the motherboard.

That is now step one of my problem solving procedure if there is any suggestion of a hardware issue. The "cold" shutdown restores all the circuitry to default so it powers up the way it is supposed to instead of the way it was left.

Another useful basic check for laptops and desktops, especially if the system won't start, is to start up with no USB or other devices attached, just the monitor. If it works, add in the other things (keyboard, mouse, printer, card reader, external USB hub) one by one, restarting each time, until either it all works or you work out what is causing the problem.