# 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 `subdates.pl` from VBA, use the routine with the VBA command Shell as follows:

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