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)
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.
Related
I found how to make this
Download_Example
I have a question about how to make execute VBS in vb6 (VBS haves form3 (from vb6 project .)show)
I made a dialog with Microsoft common dialog control 6.0
CommonDialog1.Filter = "File (*.vbs)|*.txt|All Files (*.*)|*.*"
CommonDialog1.DefaultExt = "vbs"
CommonDialog1.DialogTitle = "Select File"
CommonDialog1.ShowOpen
The FileName property gives you the variable you need to use
A work-around might be just executing the script using Shell.
Shell "wscript.exe c:\myscript.vbs", vbNormalFocus
Shell "wscript.exe " & CommonDialog1.FileName, vbNormalFocus
See Microsoft's wscript documentation.
vbNormalFocus is there to restore focus to your vb6 program. It is optional but you probably want it. See documentation.
Looks like you are trying to run a VBScript from your VB6 app to open a dialog in the VB6 app.
VB6 -> VBScript -> Same VB6
You cannot do this with Shell since it runs the script as a separate process. The Script does not know what Form3 is because it is a component of the VB6 app and would not exist as a separate entity once the app is compiled.
Edit: Looks like what you want to do is possible but with Microsoft Script Control. Here are a few examples. Thank you #GSerg for pointing this out.
This or this might be used as a work-around but I don't think it is the right way to go.
Go back to your requirements. What exactly are you trying to accomplish? There has to be a better way.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have two pst files. I want to apply all rules that are applied to first pst file to second pst file. Is it possible to do this with vbscript and without VBA. I think VBA can be run only on Outlook itself not as independent script.
I have two pst files. I want to apply all rules that are applied to first pst file to second pst file. Is it possible to do this with vbscript and without VBA.
Yes, it's possible to do this with VBScript because VBScript can use the same COM-based Outlook Office Automation API as VBA, except objects are late-bound (so if there are any typing errors in your script you won't know about them until you run it).
To convert VBA to VBScript, you need to do the following:
Copy and paste your VBA code into a *.vbs file.
Remove type information from your variable declarations
Optionally, but strongly recommended: add Option Explicit on line 1.
Change the Office COM automation interop code to use the late-bound CreateObject and GetObject functions instead of VBA/VB6-specific constructor or COM API calls.
' Change this VBA/VB6:
Set reminder = New Outlook.Reminder
' To this VBS:
Set reminder = CreateObject("Outlook.Reminder")
' Change this VBA/VB6:
Set app = Outlook.Application
' To this VBS:
Set app = GetObject("Outlook.Application")
So this VBA:
Sub Foo()
Dim foo As String
foo = ""
Dim reminder As Outlook.Reminder
Set reminder = Outlook.Application.Reminders.Item(1)
End Sub
...becomes this VBScript:
Option Explicit
Sub Foo()
Dim foo
foo = ""
Dim reminder
Set reminder = GetObject( "Outlook.Application" ).Reminders.Item(1)
End Sub
Call Foo ' Enter into the Foo() subroutine from the top-level script.
I think VBA can be run only on Outlook itself not as independent script.
This is true, however when using VBScript (when run from cscript, wscript or any other Active Scripting host, like IIS) you're still using the same Office automation API as VBA, so you still need Outlook to be installed on your computer and run the script in a normal desktop session (and not Session 0 or as a headless process). You also need to ensure your script's host has the same ISA ("bitness") as Outlook (i.e. x86 vs x64).
I am generating Excel Files with Pentaho Data Integration and I want to start a Macro automaticly after creation.
Until now, the Macro is started while opening the file.
But this is not a good way: Some users dont have permissions to execute Macros and each time you open the file Excel is asking if you want to save the changes.
I am wondering if there is a way to execute a VBA Macro in MS Excel out of the Windows Shell.
What I found is this code to open a file:
Shell "C:\Programme\Office2k\Office\EXCEL.EXE " & _"C:\...\MyExcelFile.xls"
But this is not what I want. I want to start the Macro exactly one time, and before any user opened it.
Do you have any ideas?
The solution with vbscript looks like this (Open, Save, Close without User Interaction):
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\dev\testo.xls")
objExcel.Application.Run "testo.xls!test"
objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
WScript.Quit
Is there any way to make a .vbs file Read only,so that no one rather a specific person can read the content or change the content? But only can double click on that file to start its execution. I will set up a Main.vbs into which I would put the below
Dim oShell : Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "A.VBS", 1, True
oShell.run "B.VBS", 1, True
oShell.run "C.VBS", 1, True
oShell.run "D.VBS", 1, True
The user will click only on the main.vbs to start the execution. All the .vbs I want to be Read/write protected. is my thought possible in practice?
Thanks,
If you can't read it you can't run it.
You can set permissions so that no other person (except administrators) can change the file, but you can't prevent people from being able to read the file if they're supposed to be able to run it.
Some other options to consider. The script can be encoded with the Microsoft Script Encoder. This will make it unreadable. One download link here (can't find the official Microsoft download link) http://www.softpedia.com/get/Programming/Packers-Crypters-Protectors/Microsoft-Script-Encoder.shtml. Of course, it is possible for people to decode the file using the appropriate tool.
Another option is to digitally sign the script with a code-signing certificate. This will still allow it to be viewed, but it will not be able to be modified without breaking the digital signature.
Or even encode the script then digitally sign it.
If the purpose of this is to protect your code, then you can always make an executable file.
I need an "alert" type feature to troubleshoot an error. I am not using a browser and using javascript as windows administaration purposes. So is their a way to view a varibales value if I am not using a browser?
JScript is a scripting language based on the ECMAScript standard.
JScript is implemented as a Windows Script engine. This means that it can be plugged in to any application that supports the Windows Script host, such as Internet Explorer, Active Server Pages, etc. It also means that any application supporting Windows Script can use multiple languages — JScript, VBScript, Perl, and others.
For reasons that I am not sure about, but I believe it to be related to the fact the the DOM is not available outside the browser, the alert function is also not available outside the browser. In order to popup a dialog box to the user in this case you can use the following code:
WScript.Echo('The quick brown fox jumped over the lazy dog');
If you want a windows GUI popup, then:
var timeout = 0;
var buttons = 0; // OK
var icon = 48; // Exclamation
var shell = new ActiveXObject("WScript.Shell");
shell.Popup("text ...", timeout, "window title", buttons + icon);
and run your jscript program with the wscript command.
Microsoft JScript language reference.
Popup documentation.
On windows, you can use Windows Script Host to execute your javascript. It has a built in ability to do output, using Echo. There are some nuances though, since WSH uses jscript, not javascript, though the languages are similar.
A summary of the differences between WScript.Echo and WshShell.Popup:
Windows scripts (vbs, js, wsf etc.) can be run under one of two hosts: cscript.exe (command-line), and wscript.exe (graphical). Under cscript, WScript.Echo will produce a line of text in the console window. WshShell.Popup will always produce a message window, even under cscript.
WshShell.Popup lets you specify the buttons, title and icon type, like the VB/VBS MessageBox function. It also lets you specify how long the message should remain open.
WScript.Echo lets you pass multiple string arguments to output, and will print them separated with spaces.
You can create a simple file that will alert text that is passed to it, for example in python. I don't think there is any way to do this in Javascript though without a browser.
No with javascript. You can, using Visual Basic Script and MsgBox function. No need to install anything.
'In Hello.vbs. Comments starts with '
MsgBox "Hello there"
Look at HTA files. These file types allow you to run typical HTML/VBScript/JS code without the need for a browser specifically. Just rename your HTML file to an HTA extension and run it. IT will show your "page" and execute any JS necessary. This type of file will give you access to other WScript functions as well like creating Files or accessing AD if required.