More Headlines

From this post, Tim taught me about HuddledParser 2.0. Very nifty. I can’t wait to inspect the php code, because it uses objects! Woohoo. Anyway, the IFrame is gone and replaced with calls to HuddledParser. Check out the new feed at the bottom of the sidebar.

Next, I need to make it randomly show various sites.

Daily Dose Headlines

When I was in Tucson last month, JWalk and I set up this little IFrame on his website that would show the last five entries on Daily Dose of Excel (it’s near the bottom). He had already done if for his blog, so it was it was just a challenge to see if we could hack enough php together to make it work. I didn’t expect the results I’m seeing.

On this website statistics page, it shows http://dicks-blog.com/headlines.php as the 2nd highest website referrer. I’m pretty sure John’s is the only site that uses that particular php file. And these stats aren’t just for the month, their all-time (all-time being since I started using extreme tracking back in late February). If you looked at just April, which I don’t know how to do, it would surely be the highest referrer.

I put an IFrame at the bottom of the sidebar so I can send half-a-dozen referrals his way every month. I don’t know if he’ll be able to tell they came from me, or if there’s anyway to change it so he can.

Maybe we should start an Excel RSS ring. Any Excel site with a feed can join and they all will have this IFrame showing the last five posts. Every time the user refreshes, they’d see a different sites “headlines”. Somebody set that up so I can join. :)

P.S. How do we make the background color customizable? Can I use an IFrame thingamajigger in my style sheet to override the color?

Summing Comma Separated Values in a Cell

Created by David Hager

To add comma delimited values in a cell (such as 1,2,11,4 in cell A1) to
the right of the cell containing the string, highlight cell B1 (for this
case) and create the following defined name formula (called “csum”):

=EVALUATE(SUBSTITUTE(A1,”,”,”+”))

Then, type =csum in B1 to obtain the result (18, in this case).

Defined name dialog for csum

Range showing defined name, csum, in formula

Speech in 2003

I put Office 2003 on my wife’s Thinkpad last week and I’ve been playing with it a little. This is the first time I’ve used 2003 since my tech editing days.

I set up the speech feature and did the initial training. It kept telling me to get a high-quality microphone and I kept telling it no. We just couldn’t seem to agree.

After the training, I turned on the television. That was a mistake. Apparently you need a soundproof chamber to use this feature.

Here I said “Enter text in cell”

Excel range showing text

Then I wanted to talk my way down to A2. I said “down”, it typed down. I said “enter” it typed Answer. I said “return”, it gave me a square. Ooh, that was close. Then I turned the television on and got There will.

I manually went to A2 and tried to figure out how to navigate. I said “A3?, it typed take three. It was truly a battle of wits and I was losing. I don’t remember how those ‘ones’ and ‘1s’ got in there. I was probably cursing.

Okay, maybe Excel wasn’t the right program for my test run. I opened up Word and proceeded to type the following letter: “Dear Mr. Kusleika”, “return return”, “In regard to your recent correspondence”, “comma”, ” it is my duty to inform you that your daughter was pregnant before I ever met her”, “period return return”, “Sincerely”, “comma return”, “Shotgun Charlie”

Word document showing text

It was like having my own secretary right there. If my secretary was on crack. Actually, I was pretty impressed that it got my name right and that it knew what I meant when I uttered “period”, “return”, and “comma”.

Next it was time to impress my wife and kid. “Gather ’round”, I said. I opened up a new email in Outlook and began “Dear Nancy” after which both wife and child said something to the effect of “Cool! How did you do that?” The resulting mess in the email message was less than impressive.

I wish I’d had more time to play with it. There was a lot more swearing I wanted to do. Plus I wanted to see if it knew any Spanish. Alas, my wife booted me down to my own computer where the microphone is nowhere to be found. Maybe Juan can swear in Spanish at his computer and let us know what happens.

Userform Default Instances

From Doco:

Chapter 10 of PED; “Userform Design and Best Practices”; page 303 – topic
“Use Classes, Not the Default Instance” et seq. I have read this a couple
times and wind up with the same confusion (which is a reflection on me not
the authors). It appears to me what is being stated is an instance of the
form class should be brought to bear from “within the form module” EG


Dim frmOptions AS FOptions
Set frmOptions = New FOptions

frmOptions.Show

This then would have two instances of FOptions class? I know I am missing
something – what is it?

Not from “within the form module”, but from within a standard module or another class module. You wouldn’t use the Show method from within the form’s module. This sub would exist somewhere else and serve to show the form. Do I understand your statement there?

You would only have one instance of FOptions class, the one you instantiated with the Set = New construct. VBA will not auto-instantiate a new FOptions variable unless you use FOptions somewhere else. This code, for instance, would produce two instances:

Dim frmOptions as FOptions
Set frmOptions = New FOptions
  
FOptions.Show

What VBA is really doing there is

Dim frmOptions as FOptions
Set frmOptions = New FOptions
  
If FOptions Is Nothing Then
    Set FOptions = New FOptions
End If
  
FOptions.Show

Now you have 1) frmOptions which you instantiated with Set = New and 2) FOptions which you instantiated just by using it.

FOptions is the name of a class and it’s a built-in, auto-instantiating object variable. When you use it on the right side of a Dim or Set statement, you’re using the class name. When you use it on the left side of a property or method, you are using an object variable that has the same name as a class. In your example, you only used it on the right side of a Dim and Set, so you only have one instance.

That’s harder to explain than I thought it would be. Which goes to show I really don’t know what I’m talking about. Comments, corrections, and clarifications welcome.

List Desktop Shortcuts

As you might imagine, I have several desktop shortcuts. I’ve made no secret of my hatred of all things pointy and clicky. I guess I just long for the old DOS days.

My desktop shortcuts are far from unruly. I rarely have a problem remebering one when I need it. But I do have a problem knowing which are free when I want to create a new one. I know that Adobe Acrobat is Ctrl+Alt+B, but I don’t know that U is still unused.

I can’t decide if I should assign letters based on the name of the software or its function, so I have a mishmash of both plus some that are assigned based on the predominant sound in the name rather than the first letter. That’s just a little disclaimer to prevent the comments like “Why would Adobe Acrobat be Ctrl+Alt+B?”. If you assume they make no sense, it will be a lot easier for both of us.

I started using the FileSystemObject to loop through all the files in the Desktop folder. I new that the File object had a Type property which I could compare to the string “Shortcut” to start limiting the files. I suppose I could just as easily loop through the files using the Dir function and a *.lnk filter, but I had alterior motives. I thought, incorrectly, that if the File had a Type property to help me identify shortcuts, it would have some other helpful properties for me to get the hotkey. If it does, I sure couldn’t find them.

“No problem”, I say to myself, “I’ll just use an API”. I’m not very good at finding the appropriate API for a couple of reasons: First, I’m a neophyte when it comes to APIs so I don’t have a good base of knowledge; Second, I shun MSDN whenever possible because it makes me use Internet Explorer to be able to use the left side navigation. After searching high and low, I fired up IE and searched MSDN. I really couldn’t find anything.

The story of my search is pretty boring, so I’ll cut to the chase. I found the Shell32 type library which had some promising object names. I went to the VBE, set a reference, and started Object Browsing (F2). It looks like I have everything I need, but I’m struggling to make sense of the Hotkey property of the ShellLinkObject object. I only use Control+Alt+Letter on my desktop, but I set up a couple of others for testing purposes:

Key Combo A B
Ctrl+Shift 833 834
Ctrl+Alt 1601 1602
Shift+Alt 1345 1346

According to MSDN, Shift=1, Ctrl=2, Alt=4, Extended=8. Well, I thought I was on to something when I only had Ctrl+Alt hotkeys. They all start with 16, so if 1 is a place holder and 6 is the only number that will evaluate bitwise with 2 and 4, then I must be golden. Then I did the other two combinations and threw my theory out the window. Shift+Alt should have started with 15 and Ctrl+Shift should have started with 13.

Here’s my inelegant code. If someone wants to enlighten me about the Hotkey property, that would be great.

Sub ListDTIcons()

    Dim oShell As Shell32.Shell
    Dim oFldr As Shell32.Folder
    Dim oFItm As Shell32.FolderItem
    Dim oLnk As Shell32.ShellLinkObject
    Dim i As Long
   
    Const sCS As String = “Ctrl+Shift+”
    Const sCA As String = “Ctrl+Alt+”
    Const sSA As String = “Shift+Alt+”
   
    Set oShell = New Shell32.Shell
    Set oFldr = oShell.NameSpace(ssfDESKTOP)
   
    For Each oFItm In oFldr.Items
        If oFItm.IsLink Then
            Set oLnk = oFItm.GetLink
            If oLnk.Hotkey > 1599 Then
                i = i + 1
                Sheet1.Cells(i, 1).Value = oFItm.Name
                Sheet1.Cells(i, 2).Value = oLnk.Path
                Sheet1.Cells(i, 3).Value = sCA & Chr(oLnk.Hotkey – 1599 + 63)
            ElseIf oLnk.Hotkey > 1344 Then
                i = i + 1
                Sheet1.Cells(i, 1).Value = oFItm.Name
                Sheet1.Cells(i, 2).Value = oLnk.Path
                Sheet1.Cells(i, 3).Value = sSA & Chr(oLnk.Hotkey – 1344 + 63)
            ElseIf oLnk.Hotkey > 832 Then
                i = i + 1
                Sheet1.Cells(i, 1).Value = oFItm.Name
                Sheet1.Cells(i, 2).Value = oLnk.Path
                Sheet1.Cells(i, 3).Value = sCS & Chr(oLnk.Hotkey – 832 + 63)
            End If
        End If
    Next oFItm

End Sub

Excel range showing results of macro

Don’t forget to set a reference to the Shell32 type library

References dialog showing reference set to type library

Global Defined Names

Created by Bob Umlas and David Hager

To define a global range name in Excel, go to Insert, Name, Define and, as an example, in the Names in Workbook box type “cellA1? and in the RefersTo box type this formula: =OFFSET(!$A$1,,,,).

Now, type =cellA1 in a cell on any worksheet in the workbook and it will return the value in A1 for that worksheet.

Name box showing defined name

Two windows showing different sheets using defined name


Editors note: And all this time I’ve been setting up PrevCell for each sheet in the workbook. What a chump I am.

Name box showing PrevCell

PrevCell used in a formula

Based on that, it appears that you don’t need the OFFSET function. You can define the name cellA1 as =!$A$1