Excel User Group
Microsoft Excel blogs, forums, files. Read, ask questions, provide answers.

A little library of gems for VBA

Did you know that VBA can get the user's login name, tell you where My Documents lives (and other folders), talk to the Windows registry, handle regular expressions (eg search for words of 5-8 characters starting with G), create file shortcuts, and more?

Nor did I, until I read a forum post showing how to use regular expressions in Excel, by setting a reference to the Microsoft Scripting Runtime in VBA (Tools, References from the menu). I was intrigued, and I had a look at what else this Scripting library could do. I was amazed by the range of functions it provides, including those above. You can of course use the Windows API to do most of them (although creating file shortcuts is notoriously difficult), but the Scripting library just makes them so easy. It also has some database functions.

I created a demo workbook (Scripting.xls) to demonstrate. There is no user interface, just go straight to the code (I suggest you start with the TEST_CODE module). 

PS If you don't know any VBA, and if you desperately want any of these functions, let me know and I'll help you use them.

 


Posted Jan 18 2008, 06:07 AM by dermot

Comments

Nick Hodge wrote re: A little library of gems for VBA
on Thu, Jan 17 2008 7:01 PM

Dermot

That's interesting as to the breadth of what you can do. I've only ever really needed those exposed by the environs function though.

Sub test()

Dim x As Integer

For x = 1 To 50

Debug.Print "No." & x & " " & Environ(x)

Next x

End Sub

Copyright Excel User Group and the relevant contributors, 2009. All Trade Marks acknowledged. This site is a peer-to-peer site and NOT affiliated in any way to Microsoft Corp. All rights reserved.