VBA – Determine Default Web Browser

Related to a recent question made to my VBA – Open a URL in FireFox/Chrome article and out of curiosity, I decided to figure out how one could determine which Web Browser was defined as the default web browser for a PC.

The Common Approach

I went out digging and the information I was finding simply didn’t work when I tested it. Some posts were mentioning checking the

HKEY_CLASSES_ROOT\http\shell\open\command\

and/or

HKEY_CLASSES_ROOT\https\shell\open\command\

registry key(s).

Some mentioned checking

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice

but as I said, the returned values didn’t match my settings when I’d make changes to my default app.

So I kept digging.

My Solution to Find the Default Web Browser

So what is one to do then?

Continue reading

Access – Color Picker

HTML Color Picker
In my first part of this exploration of how to enable users to make color selections within a database, I demonstrated how we can use the built-in ChooseColor API dialog. This time round, I wanted to explore using an HTML color picker. Why, you might ask, well, I wanted to see what could be used that didn’t require APIs. Furthermore, I have seen many very good JavaScript color picker and simply wanted to have some fun!

Beside not needing to mess around with APIs, conditional compilation directives, … another advantage of this approach is the simple fact that since this is built upon plain HTML, JavaScript & CSS, we can make any changes we wish to the appearance of the dialog, unlike when using the built-in Windows ChooseColor API dialog approach.
 
Continue reading

VBA – ChooseColor API x32 & x64

ChooseColor API Dialog

This is the first part, of a 2 part segment I’m working on, which explores how we can give user’s the ability to select colors within a database. In this post, I will go over using the ChooseColor API.
 

ChooseColor API

I though I’d break the code down into three versions:

  • 32-bit version
  • 64-bit version
  • Conditional Compiled version that works in both 32 and 64-bit versions

So you pick which version of the code you wish to use.

Continue reading

VBA – Retrieve Outlook Signature File

I’ve been doing some work with Outlook recently and seeing postings to read signature files that have hard codes file names

sSig = CreateObject("Scripting.FileSystemObject").GetFile(Environ("appdata") & "\Microsoft\Signatures\MySignatureFile.htm").OpenAsTextStream(1, -2).ReadAll

Now this is great and all, but that means you need to know the name of the file and update it for each user, update it should they ever create a new one … a nightmare to manage!

So I set out to find a better way!

The Nightmare That Is Outlook

I’m not going to go on and on about it, but needless to say, Microsoft sure did not make thing easy for us developers and documentation about certain aspects appears, at least to me, to be non-existent. So it took some serious investigative work to figure out which registry keys were involved, … I so wish that Microsoft would standardize and cleanup their object models and gives us some desperately needed methods and properties, but if they haven’t by now I doubt I’ll ever see it since now all their energies are on the cloud!

The fact that even with the object available to me, I still have to go through the registry to get information is just mind blowing in 2020!

Moving on now.

The Solution

The solution requires a few procedures:

  • Determine the version of Outlook the user has so we can look things up in the registry
  • Lookup values in the registry
  • Encode string as proper HTML
  • Read the signature

Continue reading

VBA – Send HTML Emails Using Outlook Automation – Improved

One of my most popular posts is my function for sending e-mail using Outlook automation: VBA – Send HTML Emails Using Outlook Automation. That said, there is an issue with that code, the way I retain the signature in the generate e-mail.

The Problem With Concatenation of .HTMLBody

Although this is the most common approach seen online (from what I have seen over the years); to concatenate the message we want to send with the existing body when the e-mail is first created:

.HTMLBody = sMyHTMLMessage & .HTMLBody

The issue being that .HTMLBody will already be a complete HTML document

<html  ...>
<head>...</head>
<body ...>
...
</body>
</html>

and the concatenation is prepending the user’s message at the beginning, outside the html/body tags, resulting in

The User's Message is prepended here!
<html  ...>
<head>...</head>
<body ...>
...
</body>
</html>

which is simply incorrect HTML!

Now, some e-mail clients, such as Outlook, deal with this just fine, but this can cause issue for others. As such, I wanted to find a way to generate an HTML e-mail while creating proper HTML.

Continue reading

VBA – Search Outlook Emails/Items

I was asked, on this blog, about how one could search the inbox for e-mails from a specific sender with a term in the subject and thought this could be a good post to help others rather than leaving the answer buried on a random post page as a comment.

The Key Concept

The important thing to know is that Outlook has the Restrict Method which enables us to perform searches and retrieve just what we are looking for. Once you are aware of this, then it’s just a question of writing some code! (luckily for you, I’ve done that!)

Continue reading

VBA – Save String To Clipboard, Get String From Clipboard

Considering some recent work I’ve done and seeing questions in forums, I thought I’d quickly illustrate how easy it is to save and retrieve strings (text) from the clipboard.

There are several possible approaches for working with the Clipboard and I will explore 3 in this post:

  • DoCmd
  • APIs
  • Microsoft Forms Data Object (FDO)

  Continue reading

VBA – Run PowerShell Command

Windows PowerShell

Have you ever wanted to run a PowerShell command from within VBA and get back a value?

Executing a PowerShell Command From VBA

Before getting into returning a response, let first look at simply executing a command. There are many instances in which we simply want to run a PowerShell command and don’t need to get any response back.

It turns out that it is very easy to do and very similar to the approach taken in VBA – Get Host IP Address.

PowerShell can simply be called/executed from a standard command prompt using the command

powershell -command

Armed with this information when can simple use a WScript Shell object to execute the command, thus giving us a simple function along the lines of

Continue reading

VBA – Create a Rule In Outlook

I recently had to do some Outlook automation for a client and decided to automate some Outlook configuration which included the creation of Outlook Rules so I thought I’d post an example here in the hopes it might help others as I found it difficult to find good examples to learn from when I needed them.

Continue reading