Category: VBS

Resize all images in a Word document with #vbs #macro

TLDR Quick and dirty macro to resize all images in a word document to 145 mm. I am lazy like that. Get the gist of it here. The “Why” Ok, so. I am a consultant, as you may know. And as a consultant, people pay me to do stuff and expect me to be efficient and deliver with high quality. Part of that entails writing documentation containing how I do stuff, where I do it and often why I do it. This documentation is expected to be detailed enough to make sure my customers will be able to follow the steps and produce a copy of my work. Most of the time these document are a big part of the disaster recovery processes and might have to be executed by the on-call staff with no previous knowledge of the product. This means screenshots. Lots of screenshots. And while templates are nice and help me out a lot, the screenshots have to be from the actual installation and not some copy-pasta from a previous assignment. To help me out, I use the excellent free program Greenshot to quickly generate screenshots into a WIP-folder (or directly into Word if that is appropriate) and that makes it possible to grab snapshots of the process without having to pause all the time to PrtScn-Alt+Tab-Ctrl+V-Crop-Ctrl+C-Alt+Tab-Ctrl+C. I simply press PrtScn and go on with the installation. Being a bit pedantic, doesn’t help me out here though as I find myself selecting and resizing all the images in the Word document I have produced. This is a very time-consuming process and not the most exact one either. I want all images to be of scaled, if necessary, to an equal maximum width that fits comfortably withing the margins of the document template my company has prepared for me. So I created a fairly simple macro to do it for me. The “How” If you are un-familiar with macros in Word, you will find them under the “View” tab. Clicking on “Macros” will give you the option to execute the ones you have, or you can create your own using VBA (Visual Basic for Applications). To create one, select where you want it saved (normal.dotx in my case, as I want it readily available) and enter a name for it. This will bring up the Visual Basic for Applications IDE, where you can write your own fun stuff.

w3Socket in VBScript

I’ve been doing quite a lot of VBScripting in a couple of projects lately. The current one requires med to connect to a couple of telnet servers and look for… stuff. Since we’re not in VB6 och .Net i cannot simply user Winsock as normally due to the lack of licensing features in VBS/WSH. Thankfully for me, Dimac has release a nifty little component for free that makes talking telnet in VBS very simple. I thought that, hey! I must share this! So here’s an example in Classic VBS: Dim oTelnetoTelnet = CreateObject(Socket.Tcp)With oTelnet.DoTelnetEmulation = True.TelnetEmulation = TTY.Host = 192.168.242.1:23.Open.WaitFor SLUSSEN login:.SendLine ANiftyUsename.WaitFor Password:.SendLine [email protected] ~ #.SendLine ifconfigMsgBox .Buffer.CloseEnd WithSet oTelnet = Nothing Not very hard at all. This one is connecting to my router (with fake user/pwd… DUH!) and there’s no support for setting the prompt type there, thus the “~ #”. The result of running this script with correct login info gives me a popup with the routers NIC-configuration.