1
votes

I have compiled 2 VBScript .vbs files in an attempt to control the use of smart quotes (also known as curly quotes) in Microsoft Word. I am experimenting with using VBScript to undertake Microsoft Word functions.

The outcome I would like is as follows: whilst having a Microsoft word document open, I would like to be able to open one of the .vbs files to turn smart quotes on effective immediately, and conversely be able to open the other .vbs file to turn smart quotes off effective immediately.

Unfortunately, whilst having a Microsoft word document open, running these scripts by double clicking the appropriate .vbs file appears to have no effect. However, if I open (by double clicking) one of the .vbs files whilst Microsoft word is closed, and then open Microsoft word, the smart quotes settings will reflect the script in the .vbs file. I have reproduced the scripts from the .vbs files below. There is a line of junk code in each one preceded by an apostrophe - as I said I have been experimenting. How do I amend the scripts to achieve the aforementioned outcome? Any assistance is greatly appreciated. Stuartzz

Script (in a .vbs file) for turning smart quotes off:

On Error Resume Next  
Set objWord = CreateObject("Word.Application")  
'objWord.Visible = True  
Set objOptions = objWord.Options  
objOptions.AutoFormatAsYouTypeReplaceQuotes = False  
objOptions.AutoFormatReplaceQuotes = False  
ObjWord.Quit  

Script (in a .vbs file) for turning smart quotes on:

On Error Resume Next  
Set objWord = CreateObject("Word.Application")  
'objWord.Visible = True  
Set objOptions = objWord.Options  
objOptions.AutoFormatAsYouTypeReplaceQuotes = True  
objOptions.AutoFormatReplaceQuotes = True  
ObjWord.Quit  

VBScript version 5.8.7601.16978 .net framework version v4.0.30319 Windows 7 Ultimate Service Pack 1 64-bit operating system Microsoft Office Professional Plus 2010 Microsoft Word 14.0.5128.5000 (64-bit)

1

1 Answers

0
votes

Using CreateObject will start a new instance of the Word application. It will not affect a currently running one. To get a currently running instance, you need to use GetObject.

So, instead of this:

Set objWord = CreateObject("Word.Application")

Use this to grab first instance of Word:

Set objWord = GetObject(, "Word.Application")

All of that being said, if you used a macro written in VBA, it would always run within the currently open file. You could even apply a toolbar button for easier access.