VBS code to create new Word document

Discussion & Support for xplorer² professional

Moderators: fgagnon, nikos, Site Mods

Post Reply
victor50
Member
Member
Posts: 41
Joined: 2007 Mar 19, 20:36

VBS code to create new Word document

Post by victor50 »

If you like to create a new document in Explorer2 first and then edit it in Word I have some script to make life easier.

First you have to create an empty new Worddocument to copy from. I put this in the folder where normal.dot resides but of course any folder will do.
Lets say the complete path is "D:\wordtemplates\new.doc"
Then create a vbs-scriptfile in some folder where you keep these handy together. Lets say the full path will be "D:\scripts\xp2newdoc.vbs". In this file copy the following script and see that the filename to be copied (after wordt=) is changed to your own path.

<start of code>

Dim shl, shf, nwfil, wordt

Set shf = Wscript.CreateObject("Scripting.FileSystemObject")
Set shl = WScript.CreateObject("WScript.Shell")
nwfil = shl.CurrentDirectory + "\"
nwfil = nwfil + "xxxxx.doc"
wordt = "D:\wordtemplates\new.doc"
strTest = shf.CopyFile(wordt,nwfil)
WScript.Sleep 500
shl.SendKeys "^Rxxxx{F2}"

<end of code>

Note: ^R is to refresh the pane. Change this to {f5} if you have substituted that key to refresh the pane.

Save the file

Now create a new Usercommand in Explorer2 (Customize). Call this newdoc and copy the following:

> D:\scripts\xp2newdoc.vbs

Don't forget the right caret!

Add a shortcutkey if you like and/or later add a button to the taskbar.
Post Reply