How to run section of VBA code in Outlook only once? - vba

I would like my VBA code in Outlook's "ThisOutlookSession" module to display a message box on the first occurrence of an event only, even if the event occurs in subsequent sessions. All the ways I have found online to achieve this are excel specific and involve changing a value of a cell and then checking this value, is there an equivalent in outlook or another way to achieve this?
I believe this could be achieved using the VBIDE library to change a variable value in the VBA code, however I would prefer not to do this.

Related

How do I focus Word document after using userform in VBA?

I have a small userform as interface to various VBA functions. I use these commonly for document automation like inserting tables formatted in certain way etc.
This works great, but I would like to have a workflow where I place the cursor at desired place, click the function, and can continue writing. Currently the form always keeps the focus after being clicked. The form is not modal.
So in image below, I have focus on (1) but want focus on (2) after VBA sub in form has completed.
I did try ending the macro with ActiveDocument.ActiveWindow.SetFocus which does not make a difference.
I could of course close the form after every macro, but I use it commonly, so this would be less preferred.
Please, try one of the two ways. Both of them have to work:
Word.Application.Activate
AppActivate ActiveDocument.ActiveWindow.Caption

Excel VBA 2010 self reference a Active X button from within it's own action

i am trying to have an active X control in Excel 2010 get it's own alternate text and display it in a Text box when it is moused over.
If i use an absolute reference .Shapes("CommandButton1").AlternativeText it gets the text and i can do what i want with it, however i want a more dynamic function so the same code can be used on multiple buttons without edits so that it will always get the initiating button's own alt text.
I found this in my research, Self-referencing from inside an Excel VBA control
It seems like it would do what i need but when i run the module it throws a Runtime error 13, Type mismatch on this line Set shpButtons(btnCount).MyButton = shp.OLEFormat.Object.Object
If it matters i am trying to do this on a MouseMove event, however when i tested the code from the previous thread i was using direct clicks to see if it would would in the first place, which it did not, giving the Type mismatch error.
Any help getting this to work would be appreciated.
Thank you all so much in advance, lin.

Excel VBA: FormulaArray error when integrated with modeFRONTIER

I have a macro that works perfectly when I run it on Excel. It's basically something like:
Range("A1:A3").formulaArray = "=myFunction(input1, input2, input3)"
When I try to integrate this macro with modeFRONTIER, I receive the error message "Unable to set the FormulaArray property of the range class". One "solution" I managed is to substitute the commas for semi-colons to separate the inputs on the VBA code, the problem then is that it works as intended on modeFRONTIER but doesn't when used in Excel!
Another detail is that I tried in another computer with the same modeFRONTIER release, project, VBA code and spreadsheet and not even the first "solution" worked.
I know it's a very specific question, but anyone had this problem (or similar) when trying to integrate excel with different softwares?

Control Button to initiate the writing of a new VBA macro

Would it be possible to have a control button (or any mechanism) that once clicked on, a textbox would appear with fields like macro name Sub "NewMacroTitle"(), a field for the date, a field for reference sources ("Getting Links/URL from a webpage-Excel VBA"found this here"), a brief description of what the macro is to do. All of these fields, except Sub "NewMacroTitle"(), would start with a ' to show a comment and all of this would be inserted into the VBA editor, or enter it into cells on a spreadsheet that could then be copied and pasted into the VBA editor.
My problem is this. I'm new to VBA. I'm also the world's worst at documenting macros. I get an idea for a macro, I'm off into the VBA editor writing away, maybe even get the macro complete. A week later I'm reviewing the macro and the first thing is "what the heck does this thing do?"
I hope you see what I'm trying to do, essentially some way to force me to document the macro before even starting the actual code.
There are tools that will add pre-defined text to the header and/or footer of a sub. I use the one from MZ Tools for error handling code and adding my name and date to the header of each proc. It is worth a look.

VBA Macro changing macro

Is it possible to create a macro in MS Office (in this case Word) that will change other macro code? I was trying to find information but no results.
I have a doc which works as a template. Content of template is changed and then saved to another file. However it is important to have current date in it. It cannot be self-updated. Those docs go to folder of people and it is important to know when they get the document, so it must be simply data (or something that does not update).
I was thinking about an on-start event macro that would input current date and on exit it would ask "Do you want self-update functionality" Yes / No
If Yes, delete that event. However I have no idea if it is possible. If it is I still don't know how to search for it.
No this is not possible. In VBA, unlike some lower level languages when you define an event you can not disable it, even using other VBA code.
In C# or VB.NET, Java or C++ you can disable an event by un-wiring it from the handler, but this is not possible in VBA.
Maybe if you be more clear on what you need I can give you a better answer.