Quick News Bit

How to use VBS to set categories for items in Outlook

0

If you miss Outlook categories, here’s how to run this VBScript procedure to get them back.

email.jpg

Image: istock/anyaberkut

Many Outlook users depended heavily on the category feature until it was removed. So, it was no big surprise when I started hearing from readers and clients about the loss. Fortunately, you can reclaim the feature. If you want to do so manually, read Reclaim Outlook categories for IMAP accounts. This technique works with any open Outlook item, not just email messages. You can do the same thing with a VBScript procedure, which I find much more efficient than using the manual route. In this article, I’ll review a simple procedure that automates reclaiming categories. I do want to stress that because this feature is no longer supported, the procedure could stop working at any time and without notice.

SEE: 83 Excel tips every user should master (TechRepublic)

I’m using Microsoft 365 on a Windows 10 system; this procedure isn’t appropriate in the online Mail app. For your convenience, you can download the .cls code module.

The VBScript procedure in Outlook

If you’re familiar with VBA but not VBScript, don’t worry. VBS is a subset of VBA. Even if you’re not familiar with VBA, you shouldn’t have any trouble adding and running this procedure. The sub procedure in Listing A is extremely simple. The only catch is that the Outlook item you are categorizing must be open.

Listing A

Public Sub SetCategory()

    ‘Displays category dialog so user can

    ‘set category to open item.

    ‘If category is unused, feature will prompt

    ‘for shortcut key selection.

    Dim OLItem As Object

    ‘Quits procedure if no item is open.

    On Error GoTo ErrorHandler

    Set OLItem = Application.ActiveInspector.CurrentItem

    OLItem.ShowCategoriesDialog

    Exit Sub

ErrorHandler:

    MsgBox “Please open the item you want to categorize.”, vbOKOnly, “Error”

    Exit Sub

End Sub

First, the code creates an Object variable named OLItem and sets it to the active (open) item. You can use this procedure to categorize any Outlook object—but it must be open for the procedure to work. The final line displays the Categories dialog, so you can set a category for the current item, OLItem. That’s all the procedure does, but you’ll continue by checking a category (color). If that category hasn’t been used before, the feature (not the code) will prompt you to set a keystroke shortcut. You can do so or cancel that prompt.

There is a bit of error-handling for those times when no item is open. The code will display a warning message box and then quit the procedure.

SEE: Windows 11: Tips on installation, security and more (free PDF) (TechRepublic)

To enter the procedure, press Alt + F11 to open the Visual Basic Editor. In the Project Explorer to the left, select ThisOutlookSession so you can run the procedure in any window. You can enter the code manually or import the downloadable .cls file. If you enter the code manually, don’t paste from this web page. Instead, copy the code into a text editor and then paste that code into the ThisOutlookSession module. Doing so will remove any phantom web characters that might otherwise cause errors.

How to use the procedure in Outlook

Before running the procedure, check the security setting by clicking the File tab and then choosing Options. At the bottom of the left pane, click Trust Center and then click Trust Center Settings in the dialog. In the left pane, click Macro Settings. You’ll have four options. Click one of the three options that allow you to execute macros, as shown in Figure A. Your level or protection depends on you and your organization; I chose Notification for All Macros. Click OK twice. If you have to change this option, close and restart Outlook before you continue.

Figure A

outlookvbssetcategory-a1.jpg

  Choose a security option that allows VBScript procedures.

Now, let’s execute the procedure as follows:

  1. Open an existing email.
  2. Click the Developer tab (if you don’t see the Developer tab, see “How to add the Developer tab” below).
  3. In the Macros group, click Macros.
  4. From the dropdown, click SetCategory (Figure B) and click Run.
  5. In the resulting dialog, choose a category color, such as blue. If blue hasn’t been chosen before, the feature (not the code) opens a second dialog that allows you to name the category and set a shortcut. Otherwise, click the Shortcut Key dropdown and choose the shortcut Ctrl + F2 (Figure C).
  6. The feature applies the blue category (Figure D).

Figure B

outlookvbssetcategory-b-2.jpg

  Execute the procedure SetCategory.

Figure C

outlookvbssetcategory-c.jpg

  Choose a category (by color) and then set a keyboard shortcut.

Figure D

outlookvbssetcategory-d.jpg

  The blue strip below the header information is the visual confirmation that you’ve categorized this email.

You can close the email when you like; it’s categorized as blue. To remove the category, open the item, right-click the category color line and choose Clear Category.

Add the Developer tab

If you don’t see the Developer tab, you can quickly display it as follows:

  1. Click the Quick Access Toolbar dropdown and choose More Commands.
  2. Click Customize Ribbon in the left pane.
  3. In the list to the right, check Developer, as shown in Figure E.
  4. Click OK.

Figure E

outlookvbssetcategory-e.jpg

  Add the Developer tab to the ribbon.

It’s unlikely that you’ll want to work through all those steps every time you want to run the procedure. Instead, add the macro to the Quick Access Toolbar. To do so, read How to add Office macros to the QAT toolbar for quick access.

Also see

For all the latest Technology News Click Here 

 For the latest news and updates, follow us on Google News

Read original article here

Denial of responsibility! NewsBit.us is an automatic aggregator around the global media. All the content are available free on Internet. We have just arranged it in one platform for educational purpose only. In each content, the hyperlink to the primary source is specified. All trademarks belong to their rightful owners, all materials to their authors. If you are the owner of the content and do not want us to publish your materials on our website, please contact us by email – [email protected]. The content will be deleted within 24 hours.

Leave a comment