I would like to know if it is possible to change the way of saving a Word document. What I want to do is have a button to save the word document which I have done successfully but if the Save button on the Ribbon or the Save\Save As option is selected a message is displayed instructing the user to save using the button on the document. How can this be done please?
What you need to do is 'catch' the Save event by adding an event handler before save happens.
Look at this post where they ask for something similar:
How to run a macro in Word before save?
It depends on you environment (Add-in, VBA, other) what exactly the eventhandler looks like but if you Google for DocumentBeforeSave you should be able to find enough examples.
Related
Good morning, I need my VBA code to run right before the TaskItem is saved, is there any way I can handle the event of saving ? I cannot find anything I could use in documentation. I am using MS-Office 2010.
Edit: I have tried
Private Sub TaskItem_Quit()
The macro disappears from macro list, but the code still does not run.
Try the Write event.
https://msdn.microsoft.com/en-us/library/office/ff868664.aspx
"Occurs when an instance of the parent object is saved, either explicitly (for example, using the Save or SaveAs methods) or implicitly (for example, in response to a prompt when closing the item's inspector)."
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.
I'd like to trigger an event as soon as the text in the (active) document changes. As I understand it, WindowSelectionChange is most suitable for this. Is this indeed the case? If so, how exactly can I use it? I've read the documentation here but I can't get my head around it, especially about which code goes in which file. Right now, I've all my code in the default module file in the "Modules" folder in the project.
FYI: I'm not really typing in the document, instead I only do Ctr+A, to select the existing content, and Ctrl+V, to replace it by new content. At that moment, I want the event to be triggered.
Although I wasn't able to find a solution for my specific question, I did find something that gave me results I wanted:
Sub EditPaste()
Selection.Paste
'Other code
End Sub
It's not quite the same as a 'text changed' event, but for me it is, because I only change the text by pasting new text. Because I named the Sub the same way as the actual paste event, this Sub is called whenever I paste something. Then, it's only a matter of adding the actual paste operation and then add your own code.
In short: instead of creating an event for an operation it's much easier to redefine the operation.
I'm working on a macro for Word which detects key words in the text while these are typed.
for example, I want that a Table will be added when the user types \table or something like that.. very similar to lyx context, but yet nothing like it.
The table example is very simple compare to the ideas I want to implement with this.
I'm looking for an event in VBA that will be triggered whenever the used types something.
There is an event called WindowSelectionChange (Reference: Event - Document Edited) but it triggers only whenever the SELECTION is changed, meaning only when the user selects another area in the document with the mouse cursor, or whenever the user moves with the keyboard arrows in the document, but doesn't triggers when the user types text (or press Enter, Space, etc...).
Seems an answer is explained here:
What events can I use to monitor users typing in Word?
Shortly - no events on type text in word: use either Windows API hooks, or assign key bindings to all keys.
I am executing code on the WindowSelectionChange event in Microsoft Word. How come when I open another document, that does not have this macro referenced in it, the code is still being called on WindowSelectionChange. I do not have the macro stored in the default template, it is stored in a template not referenced by my other word documents.
Is there a way to limit this event to the document that has the VBA code in it?
The macro events only fire unwantedly if the document that they are supposed to fire in is open at the same time. The project is stored in my own .dot file, not the default template.
Is this just the nature of binding events in word? It effects all open documents. Any ideas?
I believe the WindowSelectionChange event is called at the application level, right? So basically I think the way to fix this is to modify the code in the WindowSelectionChange so that it only executes if ActiveDocument = ThisDocument. ThisDocument is the document where your code is stored, so you can make it so the code executes only when ThisDocument is the active document in Word.
Is it possible that you made the macro in the default template instead of in the specific document?
Yes, in the macro editor, make sure your code is in the project for your document and the the one called "Normal".