Printing a sheet to pdf silently in Excel VBA

This piece of code uses Adobe Acrobat to silently print a sheet to the location you specify.
Change PDFPath and strOutFile to modify.

Dim strDefaultPrinter As String, strOutFile As String
Dim lngRegResult As Long, lngResult As Long
Dim dhcHKeyCurrentUser As Long
Dim PDFPath As String
dhcHKeyCurrentUser = &H80000001
strDefaultPrinter = Application.ActivePrinter
PDFPath = ThisWorkbook.Path & Application.PathSeparator ‘The directory in which you want to save the file
strOutFile = PDFPath & “sheet1.pdf” ‘Change the pdf file name if required. This should have the fully qualified path

lngRegResult = RegOpenKeyA(dhcHKeyCurrentUser, “SoftwareAdobeAcrobat DistillerPrinterJobControl”, lngResult)
lngRegResult = RegSetValueEx(lngResult, Application.Path & “excel.exe”, 0&, dhcRegSz, ByVal strOutFile, Len(strOutFile))
lngRegResult = RegCloseKey(lngResult)
ThisWorkbook.ActiveSheet.PrintOut copies:=1, ActivePrinter:=”Adobe PDF”

Using a passwords file with Excel VBA

With Excel VBA, to loop through a text file containing usernames and passwords use the following code. It is probably a good idea to store encrypted passwords in the passwords file.

Dim FileNum as Integer
Dim UserName as String, UserPassword as String
   If Dir(ThisWorkbook.Path & Application.PathSeparator & “passwords.txt”) = “” Then
        ‘password file does not exist. Exit with Error
        Msgbox “Password File Does not exist”
       Open ThisWorkbook.Path & Application.PathSeparator & “passwords.txt” For Input As FileNum
       ‘loop through passwords in the file till you find the one matching the client
        Dim FoundPassword As Boolean
        Dim UNameIter As String, PasswordIter As String ‘This is the values input by the user
        LoginOK = False
        While Not EOF(FileNum)
            Input #FileNum, UNameIter, PasswordIter
            If UNameIter = UserName Then
                If PasswordIter=UserPassword Then
                    ‘Login OK
                    LoginOK= True
                End If
            End If
        If LoginOK= False Then
            ‘login not ok
            Msgbox “User ID / Password do not match
            Msgbox “User ID and password are correct”
        End If
    End If

Solving Error with bzr in debian etch. PathNotChild Stack Trace

I installed bazaar on my debian box in order to host the ‘Leave Status Board’ Project on launch pad. Following the instructions to init, add, commit worked fine. But on trying to push to the launchpad account, (had to add the RSA public key to Launchpad first) I got a whole bunch of python errors, a stack trace.

bzr: ERROR: bzrlib.errors.PathNotChild: Path ‘bzr+ssh://’ is not a child of path ‘bzr+ssh://’

Traceback (most recent call last):
File “/usr/lib/python2.4/site-packages/bzrlib/”, line 611, in run_bzr_catch_errors
return run_bzr(argv)
File “/usr/lib/python2.4/site-packages/bzrlib/”, line 573, in run_bzr
ret = run(*run_argv)
File “/usr/lib/python2.4/site-packages/bzrlib/”, line 282, in run_argv_aliases
File “/usr/lib/python2.4/site-packages/bzrlib/”, line 601, in run
relurl = to_transport.relpath(location_url)
File “/usr/lib/python2.4/site-packages/bzrlib/transport/”, line 375, in relpath
raise errors.PathNotChild(abspath, self.base)
PathNotChild: Path ‘bzr+ssh://’ is not a child of path ‘bzr+ssh://’

bzr 0.11.0 on python (linux2)
arguments: ['/usr/bin/bzr', 'push', 'bzr+ssh://']

** please send this report to

A helpful soul at irc ( mentioned that 0.11-1.1 version of bazaar that I had installed was quite old. Considering that 1.11 is the current version, that was actually quite old.

A quick trip to for the stable version for i386 with a download with wget got me the deb installer.

Uninstall the old version, install the deb file. A minor hiccup was the python-celementtree needed to be installed, which I did. The installer also complained about python 2.5 required, while my system had 2.4. But didn’t stop installing.

Pushing to launchpad works fine for now, so I take it that python 2.4 is quite ok for this version of bzr.

Recovering Files from Damaged Camera Card

There was an important event this week at the workplace and we had called in a photographer to take some snaps for the press. After the event, to his horror, he finds that his card won’t open on any computer. Pretty scary huh? He seems to have used a pretty old card and though the card still showed all the images in his Nikon camera, it wouldn’t mount in any card reader. Directly connecting the camera with the cable didn’t work either. A dmesg run on ubuntu showed lots of IO errors, which seemed to be physical damage on the storage area. Since the errors were clustered near each other I was sure that the entire card was not a write-off. Well the event was quite important so I had to find a way to get the images out of the card.

A bit of googling got me lucky. Zero Assumption Software has a product called Zero Access Recovery (Download Link) which, though it is a trial version, has the photo recovery part as a fully functional component in the trial version. So technically the photo recovery software is freeware. The software first asks you to select the card, (I put the card in the card reader and though windows couldn’t mount it, it kept running autorun repeatedly some reason), scans it for damaged areas (this takes ages…) and then lists all files which can be recovered. Be prepared for a long wait though. It took me 1 1/2 hours for the 512 mb card. The software even lets you make a disk image of the card, but I couldn’t figure out a way to use the image.

More luck and I was able to recover most of the photos losing only three of them. And the photographer was actually quite impressed with my ‘technical prowess’ as he called it. Well, that is one satisfied user. :)

CorelDraw Error: Required Resource was Unavailable

When CorelDraw X3 gives the error dialog “Required Resource was unavailable” on clicking the New or Open links on the Welcome Page, it probably is because the User’s preferences is corrupt.
To confirm, create a new account, login to that and try opening Coreldraw. If you are able to create a new file, then you need to flush out the Applications, User preferences.
To do so, close Corel first, open C:/Documents and Settings/Application Data and delete the Corel Folder.
When you restart Corel, the preferences will be regenerated and it should open fine.

Update: Coreldraw seemed to show only a few fonts when using the text tool. Disabling “Use only document fonts”  in Tools>options>font options fixed that.