Opening .bat file from Outlook VBA - vba

I am trying to open a .bat file from outlook VBA. My code worked until this last week.
Here is the Code:
Sub Daily_batch_file(Mail As MailItem)
Call Shell("P:\my path\my bat.bat", vbNormalFocus)
End Sub
I have a rule that kicks this script off when I receive a particular email. I am getting an invalid call error but haven't been able to figure it out. Any suggestions?

Instead of call .bat file from VBA, maybe you can open it using Rule from outlook. It's pretty simple.
Just create a blank rule with the specific word in the subject/body (or you can choose any condition based on your situation). And then in the Select Action window, tick the "Start Application" and then find your .bat/.exe file.
I hope it's clear enough.
Thanks

Related

How to create a macro to jump to the end of a document in Libre Office Basic

Each time I open my Libre Office document to add updates, I have to press CTRL+END to jump to the bottom of the document. I thought of adding a button to jump-to-the-bottom, but the Basic it uses is not VBA, so I'm in a pickle. Can anyone give me a sub?
As an after-thought; can I add an instruction to the document-startup?? to cursor-jump-to-the-bottom of the file? Please forgive my pants naming conventions, I'm still green!
I tried the offline help to no avail. Next I tried Google but could not find an exact sub to match. I then subscribed to the TheDocumentFoundation and was presented with an SO-like Q&A forum. The discobot did not help!
I also tried recording a macro which does work ok. The sub code is:
sub Main
rem define variables
dim document as object
dim dispatcher as object
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dispatcher.executeDispatch(document, ".uno:GoToEndOfDoc", "", 0, Array())
end sub
I cannot however add the commands to the document.init or startup.
In fact, the macro for moving the cursor to the end of the document is a little easier to write. Each document has a controller. The text document controller has a "view cursor". You can control this cursor using its methods, in this case you need the .gotoEnd() method.
So the code can be like this: "if this document is a text document, then get its controller, take the cursor from the controller, make the cursor jump to the end of the text"
Sub jumpToEnd(Optional oEvent As Variant)
If ThisComponent.SupportsService("com.sun.star.text.TextDocument") Then
ThisComponent.getCurrentController().getViewCursor().gotoEnd(False)
EndIf
End Sub
The best place for this macro is some module in the Standard library under "My Macros" - this library will be loaded immediately after starting the office and macros will be available for execution at any time. (If you want to run this macro only for one document, then you can place it in the Standard library of this document)
To run the macro automatically, use the Tools - Customize - Events tab
This is where you specify whether the macro should be executed when you open one specific document or when you open any document.
Now that you know how to do this, you will probably agree that pressing Ctrl+End is much easier.

Create and Run Macro in Excel 2010 using VBS file

I have written a macro in excel that carries out the actions I need. However the issue comes in when I need the macro to be run in a new download. Obviously the macro will not be in this file. What I want to create is a file that will allow me to run this macro without having to copy and paste every time. After doing some research, I have found out this could be possible via a VBScript file. I have researched 2 methods and can't get either to work. They are, to open the file and try and execute the macro using a call function, and having the macro within the VBS File (I have made all the changes to the macro I know of to try and make it VBS) and the other method is to use the VBS file to create a new module and add the Macro code into the file. But I can't get anything to work. I can get the file to open and do little silly things like pop up messages, but that's all I have managed. Any help will be appreciated :) Thanks
(the question that is the same as mine, can someone explain what is happening with it, because I have looked at it and there is hardly any of it that I can follow)

Run Macro on specific static file when macro workbook is opened

I have a VBA Macro that I need to run on a CSV file that always has the same name and is always in the same location. Is there a way I can get it to automatically run the macro on the specified csv file as soon as the macro file is opened? Thanks in advance!
Yep, pop it in the Workbook_Open event. To do this open VBA, make sure you can see the Project Explorer, double click on ThisWorkbook, click the drop down that currently says General and change it to Workbook and put your code in there.

Excel VBA - Call macro using add in

I have added a toolbar menu for my macro, so I can just press the button and it runs my macro from any excel document. Every time I run the macro though, it opens the source file containing the macro. Is there a way that it won't open the source file and just run the macro? (even opening and closing wouldn't too much of an issue, but I'd prefer not opening it at all)
I haven't been able to find any information about this, so all help to get me started is appreciated.
You can't pull code out of the air to run it; Excel's going to have to open the file the code's stored in to run the code.
If I understand it correctly, you can create an Excel add-in from your code and have the add-in load automatically when Excel starts. Your code will always be available in that case.
This seems like a good place to start:
http://msdn.microsoft.com/en-us/library/aa140990(v=office.10).aspx
USE YOUR PERSONAL MACRO WORKBOOK
Open the VBEditor and find the module containing your macro.
Copy that code.
Now in the VBProject Panel on the left, locate your PERSONAL.XLS or PERSONAL.XLSB project. This is the project where you store macros you want available at all times. Add a module to that project and put your code into it.
Now update your "button" so that it points to the macro in that workbook and you're good to go.
On the off chance your PERSONAL.XLS project does not exist, use the macro recorder to record a "junk" macro and be sure to set it to "Store Macro In: Personal Macro Workbook"... that will create it for you the first time.

Problem Getting Outlook 2007 Running VBA Script

I'm trying to get Outlook to save the attachment in a daily email to a folder where I can have a file system watcher ready to parse and analyze the attachment (it's the report of a data integrity checker). I've set up a Rule that is supposed to run a VBA script, but it just doesn't run as far as I can tell. I've verified in VB6 that the code will in fact save some text to a file, so if Outlook actually runs the VBA script it should be able to do the same. But it doesn't! Can anyone see what the heck I'm doing wrong?
Dim WithEvents objInbox As Outlook.Items
Private Sub Application_Startup()
Set objInbox = Session.GetDefaultFolder(olFolderInbox).Items
End Sub
Sub SnagAttachment(theItem As MailItem)
On Error Resume Next
Dim fnum As Integer
fnum = FreeFile()
Open "c:\temp\success.txt" For Output As #fnum
Print #fnum, "Ran SnagAttachment Successfully"
Close #fnum
End Sub
Note that when I use the Rules wizard, and choose "run a script" the Sub SnagAttachment is listed as a script that can be selected.
How would you know if it's working or not when you put On Error Resume Next at the top of the procedure? You would never find out.
Here are the rules for creating a script that should be run as part of a Rule:
How to create a script for the Rules Wizard in Outlook
Also note the caveat found at How to process incoming messages in Microsoft Outlook:
A "run a script" rule is not a good choice for heavy traffic
applications, as Outlook is likely to skip applying the rule if too
many items arrive that meet the rule's conditions.
In order to get the script to work you need to change the security settings in Outlook. Go to Tools > Macro > Security and change it to "Warnings for all macros". Then restart Outlook.
Hope this helps
Try isolating the exact problem:
Check macro security settings. At maximum, it must be set no higher than "Warnings for all macros".
Try creating a new module with a single test sub:
Sub Test(Item as Outlook.MailItem)
MsgBox "test"
End Sub
Then set up a new rule to handle _all_ incoming messages running this sub as the only action, and temporarily disable all other rules. Then send a message to yourself. If you get no popup box as a result, this may be an indication of a bad Outlook install. Try reinstalling it, or calling MS up directly for support.
If the previous test was successful, try working with the `Scripting.FileSystemObject` object instead of `Freefile()` to create and populate files. This is just to test if there's some odd bug you're encountering here. Worth a shot, right?
Make sure your rule conditions are set correctly. There could be a glitch or misspelling in a condition which just drops all messages you want this script to run on.
I was experiencing the same issue, and it seems to me that if there is an error in your code, the script will not even start. This is as opposed to standard VBA where the debugger pops up for runtime errors. For example, I had a label at the end of my function that was missing the colon after it. This caused the script to not run at all (As opposed to running up to this line and then failing). I would suggest commenting out all of your code and starting with just a msgbox "hello world". I would leave this in your code as you debug it to know the code is running, but you will probably have to dismiss the message box many times. Iteratively add back lines of code until you discover where the problem is.