Run a Perl interpreter from Microsoft Word

This VBA gives a subroutine, PerlString, which runs a Perl script under a Perl interpreter, here wperl.exe.

Function PerlString(Script As String, Optional args As String = "")
' Returns a string to pass to Shell in order to run a script.
' Call this with the name of the script to run,
' which should be something in C:\Users\ben\bin, and
' the arguments to the script.
Dim ScriptPath As String
ScriptPath = "C:\Users\ben\bin\" & Script
PerlString = """C:\Perl\bin\wperl.exe""" & _
    " """ & ScriptPath & """ """ & args & """"
End Function

To run a Perl script called from VBA, use the routine with the VBA command Shell as follows:

Sub SubstituteDates()
    Dim PerlPath As String
    PerlPath = PerlString("")
    RetVal = Shell(PerlPath, vbNormalFocus)
End Sub

Web links

Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock ( or use the discussion group at Google Groups. / Privacy / Disclaimer