Archive for the ‘Tips’ Category

Macro to add a hyperlink to a mail message

February 13, 2008

Today I wrote a mail to someone and wanted to add several links. It always annoyed me that Office’s Add Hyperlink is so bloated it takes some time to open, and even more time to switch back to it from another application, where all I wanted was to make the selected text link to the URL I had in my clipboard. So I set out to write a macro that did it.

Since Outlook has no macro recorder, I started searching Outlook’s Object Browser and discovered that there is no method to add a hyperlink or to get the content of the clipboard. So I borrowed the “Getting clipboard content” functionality from a VBS script I already had, and I turned to Word to record a macro that adds a hyperlink to the selected text. Once I had this Word macro, I found out I can use ActiveInspector.WordEditor to issue the Word macro I created.

The final macro result is this:

Public Sub AddLinkFromClipboard()
    If ActiveInspector.EditorType = olEditorText Then
        MsgBox "Can't add links to textual mail"
        Exit Sub
    End If
    Dim objHTM As Object
    Dim ClipboardData As String
    Dim doc As Object
    Dim sel As Object
    Set objHTM = CreateObject("htmlfile")
    ClipboardData = objHTM.ParentWindow.ClipboardData.GetData("text")
    Set doc = ActiveInspector.WordEditor
    Set sel = doc.Application.Selection
    doc.Hyperlinks.Add Anchor:=sel.Range, _
        Address:=ClipboardData, _
        SubAddress:="", _
        ScreenTip:="", _
        TextToDisplay:=sel.Text
End Sub
Advertisements

KatMouse enables mouse wheel for VB6 and Remedy

May 7, 2007

Via LiefHacker, I just found KatMouse.

The main goal of this small utility is to enable scrolling with the mouse wheel in windows that don’t have the keyboard focus.

But I mainly find it useful to use the mouse wheel in applications that don’t handle mouse wheel event. Up until now, I found two such applications that I use – Visual Basic 6, in which I still fill at home for some quick tasks like testing our COM class library, and Remedy User which we recently switched to for customer support and bug tracking.

KatMouse simply sends the correct message to those application and makes the mouse wheel works for them. I did find some problems with it – it disabled the mouse wheel in Excel 2007 worksheets and in Word 2007 Document Map sidebar. Fortunately, KatMouse provides an ultra-easy way to configure it to ignore specific window classes, using a Spy++ like windows finder, so the problem was quickly and easily solved.

The only problem that still remains is that my Dell D620 mouse-pad doesn’t have a mouse wheel… :(

Update: There is one problem I found with KatMouse which I couldn’t resolve. In Excel 2007, when you do data filtering, and click the arrow at one of the title cells, you get a complex menu with some options like sort and advanced filtering, and also a list of all values in the column so you can select from it. This list doesn’t handle mouse wheel events. It didn’t bother me until now – like any window with no wheel support, I’d try using the mouse wheel, and when it didn’t work, I would scroll with the scrollbar. However, when KatMouse is active, using the mouse wheel causes the special filter menu to disappear. The problem is I can’t find out how to tell KatMouse not to handle mouse wheel events for this menu, as it disappears on every mouse click or key down, so I can’t get its window class. Not such a big nuisance, but nevertheless…

Update 2: One additional place I found KatMouse useful is with DiskFrontier which does not support mouse wheel which tends to be really annoying. A quick class customization in KatMouse solved the old problem.

Update 3 (25/12/2008): When I recently showed KatMouse to a colleauge, I went to KatMouse homepage, and noticed that version 1.04 was released shortly after this post was published. This version adds support to Office 2007, and solves the annoying problem mentioned in the first update and adds mouse wheel support to Excel 2007 filter menu.

Second rename command in Total Commander

May 7, 2007

I use Total Commander to manage my files. I find it invaluable. Today, I accidentally discovered a great feature it has which I was not aware of.

One of the nuisances of renaming a file is to remember to keep the extension, since when I enter the “inplace rename” mode, the entire filename can be edited, including the extension.

I just noticed that when I repeat the command that starts the “inplace rename” mode, only the filename without the extension is selected, which makes it very handy to rename the file while keeping the extension.

From my tests, this only works if you use the keyboard shortcut to start the “inplace rename” mode. By default it is Shift-F6. In my configuration, F2 also does the same thing, to be compatible with Windows Explorer. However, other methods to enter the “inplace rename” mode, such as clicking the report name twice or using File menu -> Basic File Handling -> Rename (Inline) doesn’t have this effect.

Searching some more, I noticed this is explicitly mentioned in the online help, in the “F6: Rename / Move” topic. It also mention another nice feature:

When renaming a ZIP file to an EXE file, Total Commander will ask if you want to create a self extracting ZIP archive. If you choose ‘yes’, the EXE file will be converted.