Category Archives: MS Word

Get Printer Information Using PowerShell Via VBA

In today’s post, I thought I’d explore Printers via PowerShell a little.

  • Have you ever needed to determine what printers where installed on a PC?
  • Have you ever needed to determine the default printer on a PC?
  • Have you ever needed to stop, or start, the print spooler?

All these things are easy to accomplish with PowerShell.

Note that the functions provided below rely on my PS_GetOutput() function which is part of my post VBA – Run PowerShell Command.

Continue reading

Get a List of Installed Programs Using VBA and PowerShell

Ever wanted to retrieve a listing of Installed Software on a PC?
Ever needed to confirm whether a application was installed on a PC?

If you Google the subject you can find discussions and post that get into using APIs, …

Today, however, I thought I’d continue investigating how PowerShell might be able to simplify this task.

Continue reading

How to Get Windows OS Information Using VBA

I’ve previously touched upon this subject back in 2016 in my post entitled VBA – Determine the Installed OS.

That said, today, I thought I’d demonstrate 2 possible approaches to retrieving Windows OS information using:

  • PowerShell via VBA
  • Plain VBA

and dig in a little more into the subject to show various functions that can be used and how they compare to one another at the end of the day.

In both instances, we are calling WMI to get system information. In this instance, we can get Windows OS information by querying the Win32_OperatingSystem class as it exposes a whole slew of OS properties, such as:

Property Example of returned Value Comment
Caption Microsoft Windows 10 Home There is also a Name property but include Harddrive info for example ‘Microsoft Windows 10 Home|C:\WINDOWS|\Device\Harddisk0\Partition2’, so IMHO Caption is what most peopl would be considered the name.
OSArchitecture 64-bit
Version 10.0.19043
BuildNumber 19043
OSLanguage 1033
WindowsDirectory C:\WINDOWS

Check the official documentation, a link is provided below, for a complete listing of all the available properties.

Why?

Some people have asked me why we would need to gather such information. The reason is quite simple, this information can be useful when providing support to end-users and can assist in troubleshooting and isolating environment issues. I typically include this information as part of my error logging routine.

It makes sense to have this automatically retrieved through your application were it could be copy/paste, automatically e-mailed, … so your end-users don’t need to find a way to locate the information themselves. We always need to remember that not everyone is comfortable with computers and if we can simplify things for our end-users, we should take the opportunity to do so!

Retrieving Windows OS Information Using PowerShell

Since I’ve been doing a lot of work exploring extending VBA’s capabilities by using PowerShell through VBA, I thought it natural to see if such information could easily be accessed. As with my other VBA/PowerShell posts, such information is very easily retrieved.

These PowerShell functions all require a copy of my PS_GetOutput function which can be found in my post VBA – Run PowerShell Command.

So let’s explore how we can retrieve each property individually and then how we can get them all in a single call.

Continue reading

Determine the Office Update Channel

Another critical element to determine to be able to provide support to an end-user is their Office Update Channel as it dictates what updates, build no., are available to them. So this is required to know if their installation is up-to-date, or not.

I came across a webpage that indicated the fact that each Update Channel used a different URL. With this information in hand, I figure we could build a function to cross-reference the PC’s URL against the list to determine the current update channel.

Below is what I came up with.

Continue reading

Determine the Program’s Release Type

More than ever, with MS365 (previously Office 365), it is very important to easily be able to determine the release type (Volume License, Retail, Trial, …) of the Office installation as the different Release Types have different update schedules. Furthermore, what I have come to understand is that many users have no clue about Release Type nor how they can ascertain theirs.

This is the type of information along with things like the Bitness or Build No that anyone providing end-user support needs.

Today, I thought I’d offer a simple VBA function that can easily get this for us!

Continue reading

How to Print Files in VBA Without APIs

As I continue to delve into PowerShell I have been successfully eliminating the need for several APIs in my code base to eliminate things like

  • APIs
  • Enums
  • Conditional Compilation Directives
  • Versioning issues/Missing References

In the past I have always printed documents by simply using the ExecuteFile function found in my article VBA – Opening Files and URLs.

PowerShell Printing a Single File

Once again, PowerShell makes it extremely easy to print a file and performs this action with a single line of code, as shown below:

Start-Process -FilePath 'C:\Users\Dev\Documents\PowerShell.docx' -Verb Print

Thus, we can build a simple VBA wrapper like:
Continue reading

Get Image Exif Properties using VBA and PowerShell

In this article I thought I’d look at how we could retrieve Image Exif property values using VBA and PowerShell.

EXIF

What is contained in the Exif properties?

Well EXIF contains all sorts of ‘extra’ information pertaining to a file. What exactly depends on the original source of the file, and whether it has been edited. So that is to say that it can vary from images, mp3, … It will even vary between cameras used to take pictures.

Also note that some people also refer to this as a file’s meta data.

Here’s an example of what I retrieved for a sample image

Filename              : DSC_0860.JPG
Height                : ‎680 pixels
Date taken            : ‎10/‎27/‎2018 ‏‎6:37 PM
Item type             : JPG File
Metering mode         : Pattern
Space used            : ‎91%
File extension        : .JPG
Flash mode            : No flash, auto
Owner                 : MSI\Dev
Dimensions            : ‪1024 x 680‬
Vertical resolution   : ‎300 dpi
Name                  : DSC_0860.JPG
Light source          : Unknown
Folder                : 111APPLE (D:\Pictures\)
Width                 : ‎1024 pixels
Program name          : Ver.1.00 
Focal length          : ‎102 mm
Date accessed         : 10/22/2021 7:37 PM
Size                  : 447 KB
Path                  : D:\Pictures\111APPLE\DSC_0860.JPG
Date modified         : 10/28/2018 5:25 PM
Date created          : 1/22/2021 8:28 PM
Link status           : Unresolved
Shared                : No
Max aperture          : 4.4
Exposure time         : ‎1/200 sec.
Folder path           : D:\Pictures\111APPLE
Horizontal resolution : ‎300 dpi
Computer              : MSI (this PC)
Comments              :                                     
Exposure program      : Unknown
Attributes            : A
Total size            : 910 GB
Folder name           : 111APPLE
White balance         : Auto
EXIF version          : 0221
Space free            : 74.6 GB
Type                  : JPG File
Program mode          : Not defined
Bit depth             : 24
ISO speed             : ISO-1600
35mm focal length     : 153
F-stop                : f/4.5
Rating                : Unrated
Saturation            : Normal
Orientation           : Normal
Camera model          : NIKON D90
Exposure bias         : ‎0 step
Kind                  : Picture
Perceived type        : Image
Camera maker          : NIKON CORPORATION

As you can see, there is a treasure trove of information. It can even include things like Longitude, Latitude, … so it can contain sensitive information allowing people trace Who, Where, When.

Retrieving EXIF information via VBA

I was initially encouraged when I saw I could easily get image size value by simply doing:

[System.Drawing.Image]::FromFile('C:\Users\Documents\Test.jpg').Size.Height

and

[System.Drawing.Image]::FromFile('C:\Users\Documents\Test.jpg').Size.Width

I thought that perhaps it was that easy to do in PowerShell. Sadly, that was the extent of that technique; 2 available properties and no exif properties. Oh Well.

So I got digging and ended up creating the following:
Continue reading

Get Environment and System Variables using VBA and PowerShell

In my continuing quest to build a PowerShell library, today I thought I’d look at how we can possibly use PowerShell, through VBA, to get various environment and system variable values.

I’ve somewhat touched upon this subject in the past in articles like

PowerShell

Why PowerShell exactly?

I think by now I have clearly proven the extreme power of PowerShell and the fact that we can tap into this through VBA is actually spectacular! Now, there is nothing wrong with some existing approaches, but there are many others that PowerShell is simply better. With PowerShell we don’t need to mess with

  • bitness/conditional compilation
  • APIs

PowerShell is surprisingly fast!

So you get what you want without any of the disadvantages of some of the other solutions.

Like everything else in life, you need to evaluate for yourself if this helps or hinders your development. For me, by adding the 2 function: PS_Execute and PS_GetOutput from VBA – Run PowerShell Command I have been able to eliminate many of my common APIs and streamline my code base. This simply makes my solution more stable and as indicate earlier, some PowerShell solution are faster, which makes users happy.
Continue reading

How to Zip and Unzip Files Using VBA

I know, I know, you’ve already seen code that can zip and unzip files. Things like:

but, I thought, that perhaps we could explore a newer, and perhaps easier, approach today.

PowerShell to the Rescue!?

A short while back, for fun, I explored invoking PowerShell commands through VBA and created a series of procedures and shared them in my article entitles VBA – Run PowerShell Command.  Since then, I’ve furthered my education in PowerShell and have had my eyes opened to its true power and simplicity (once you understand the basics).  PowerShell basically can do everything on a PC (Networking, Hardware, ActiveDirectory, Events, …), once you know which cmdlet to use!

So I thought I’d take a second look at a common need zipping/unzipping and see if PowerShell could possibly simplify a developers life.

What I found out was the fact that PowerShell can perform either of these action using a single line of code!  No APIs, dlls or convoluted modules.

So combining the PS_Execute() sub from VBA – Run PowerShell Command with either of these commands and we have the ability to create zip files or extract the content of a zip file with 1 line of code.

Below are 2 procedures I created to illustrated how this can be done.

Continue reading

Office 2021 / Access 2021

If you weren’t already aware, earlier this month both Windows 11 and Office 2021 were released.

I’ve been involved in a couple discussions regarding Office 2021 regarding what it offers and where we can get it.

What’s New in Access 2021?

Continue reading