VBS doesn't open Outlook - vbscript

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

Related

Moving saved e-mails from a shared folder to outlook sub-folder

In our company we follow a process where in a team saves e-mails in a shared folder from where people from another team are supposed to pick and start processing. As a improvement idea I was looking for a macro which upon triggering can loop through all the saved e-mails in that folder and can save or bring them in a outlook sub-folder of the processor's inbox of this team.
I have tried and figured out a code from internet which can copy files from one folder to another (please see below) but could not get to modify it to save the .msg files in the outlook subfolder. This is doable manually so was thinking there should be a macro as well which can do it automatically.
Any help will be highly appreciated. Thank you in advance .
Sub Download_sub()
Application.EnableCancelKey = xlDisabled
'downloads the submission mail item into users download folder
Set fobj = CreateObject("Scripting.FileSystemObject") 'create the file system object
fobj.CopyFolder sht_Databases.Range("B21").Value & "\MailFolder" & _
, sht_Databases.Range("B22").Value
Set fobj = Nothing 'release the variable
End Sub
You can use
Application.CreateItemFromTemplate and pass the folder as the second parameter. Note that the message will be created in the unsent state and no sender properties will be copied.
Namespace.OpenSharedItem to open an MSG file, then copy it to a given folder using MailItem.Move().

Word.Application SaveCopyAs Unknown runtime error: 800A1704

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

How to add a license key through VB Script?

i am new to the vb script. I have installed a program and have to call an License.exe and fill the License name and license key. Batch file to add it into the reg key is not working on this app. So it would be great if you can help me in this.When i open the License.exe with installed product . it asks me to fill License Name and the License Key. I dont know how to create to add that key through script but i was able to call the .exe. here is an example.
Dim objShell
Dim StrLicensename
Dim StrLicensekey
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run("""C:\ProgramFiles\Resources\licensing.exe""")
StrLicensename = CStr("Melbourne Victoria")
StrLicensekey = Cstr("1234-4567835")
Set objShell = Nothing
Any help would be much appreciated.
Thank you in advance.
Well we need to package it and deploy through SCCM. Thats the reason our team was thinking to do ao rather than activating 50 machines manually.

convert msg to html in background using vbscript

I'm converting an Outlook msg file to an html file. So far I have:
Dim objshell,BaseName,outlookapp,emailPath
Set objshell= CreateObject("scripting.filesystemobject")
Set outlookapp = CreateObject("Outlook.Application")
Set email = outlookapp.CreateItemFromTemplate(emailPath)
emailPath = "C:\Users\makkerman\Desktop\email folder\test.msg"
BaseName = objshell.GetBaseName(emailPath)
email.saveas objshell.GetParentFolderName(emailPath) & "\" & BaseName & ".html", 5
outlookapp.Quit
I'd like this to run in the background (without disturbing the user who runs it). Do I have to start an Outlook process? As it currently stands, if the user has Outlook open, then the above script closes Outlook and I can understand why (outlookapp.Quit). If Outlook isn't open when the script is run, Outlook opens for the script's duration.
Can someone please nudge me in the right direction? Thank you!
Why do you need to call Application.Quit? If Outlook was running, it will stay running. If it was not running, Outlook will close itself when you de-reference all Outlook objects - keep in mind that Outlook is a singleton and CreateObject will connect to the already running instance; you do not get a brand new process.
If you do not want to use Outlook, you can use Redemption (I am its author, it will not start Outlook):
set Session = CreateObject("Redemption.RDOSession")
set Msg = Session.GetMessageFromMsgFile("c:\temp\test.msg")
Msg.SaveAs "c:\temp\test.html", 5
I would create an instance of Outlook regardless if it's open or not. This should help: Run program minimized. Make sure to check out the docs link in the answer to get all parameter options.

Executing VBA out of Shell

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

Resources