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).
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.
When calling a external .exe file from vba, like this:
Sub RunEXE()
Dim wsh As Object
SetCurrentDirectory "\\path\" 'Set Directory
Set wsh = VBA.CreateObject("program.exe ""\\path\argument""", WindowStyle:=1, waitonreturn:=True)
Is it possible to close error windows directly from VBA?
The code calls the program and correctly runs the .exe and produces all of the data that is useful to me, but to get the data back to my sheet I have to okay this window (since waitonreturn=true):
The violation appears to be something I can't impact from my VBA code, but it is not impacting the section of the .exe I need in order to do the calculations required by my code. Instead of delving into the world of memory access violation of an external piece of software, I am hoping to side step the problem by okaying it direct from the VBA code.
If I click okay on that error message everything is perfect as far as my code is concerned. I don't need the .exe to save the files causing the error, and I already have the data I need.
Is it possible to dismiss an error window from external software from my excel-VBA code?
NOTE: The error comes from the .exe program, not from excel itself.
This is a simple example of sendkeys, which will open notepad and then send an Enter key:
Sub SendEnterToNotepad()
With Application
Shell "Notepad.exe", 3
SendKeys "{ENTER}"
End With
End Sub
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.
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.