I wrote a VBScript to convert Word 97-2003 Documents to Word 2016 Documents (I have Microsoft Office 2016 installed on Windows 10 v1709, 64-bit Enterprise).
Here's the minimal code to reproduce the problem:
Dim Word, DOC, FSO, Dir
Set Word = CreateObject("Word.Application")
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Dir = FSO.GetFolder(".")
Dim FileName
FileName = Dir.Path & "\test.doc"
Set DOC = Word.Documents.Open(FileName)
DOC.SaveCopyAs FileName & "x"
DOC.Close
Word.Quit
Open Word, create a blank document and save it as "Word 97-2003 Document" with the file name being test.doc and place it under the same directory as the VBScript. Then run the script.
However, if you slightly modify the above script and try to convert .xls to .xlsx or .ppt to .pptx, it works. Actually that code is modified from a fully working PPT to PPTX converter that I wrote earlier. It worked very well without any problems with PowerPoint 2016 on the same system. Another modification to make an XLS to XLSX converter also worked with Excel 2016.
My Google-fu did no useful job, nor did re-installing Office 2016 help. I also tried on 2 other computers with freshly installed Windows 10 v1709 Enterprise and Office 2016 (both 64-bit), and the same error showed up.
Any idea how can I save that as DOCX with the current VBScript?
Just by recording a macro, the following code was generated for saving the word from .doc to .docx extension
DOC.SaveAs2 FileName &"x",12,,,,,,,,,,15 'FileFormat = 12; WdSaveFormat =15
Related
I try to run a vbs to open Outlook after i scanned a doc, it scans the document on Windows 10, but doesn't open Outlook, have you guys any idea?
BR Alex
Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
Set objOutlookAttach = objOutlookMsg.Attachments.Add(output)
objOutlookMsg.Display
Reason was a missing permission on the folder where the scanned file was stored
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 have written a VBScript that helps me organise my desktop every time it gets messy.
It works fine it moves my files and shortcuts based on the extension and the name of the app. However, I have a few app shortcut links that just won't move. in fact the vbs script will not even see them with this basic script
Set FSO = CreateObject("Scripting.FileSystemObject")
dir = CreateObject("Scripting.FileSystemObject").GetParentFolderName(WScript.ScriptFullName)
Set folder = FSO.GetFolder(dir)
Set files = folder.Files
For Each file in files
MsgBox file.Name
Next
The files in question are all shortcuts they are iTunes, VLC, Google Chrome and WinRar.
Is there anything I can check to see why vbs won't even see these files?
What You can see on your desktop is hybrid view of two folders:
C:\Users\YourUsername\Desktop
C:\Users\Public\Desktop
Where the Public one is usually a place, where shortcuts are being created during app install, so all users do have them. In your script You are only looking for files in the YourUserName\Desktop, that's why the script does not see those shortcuts.
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
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.