Creating buttons or front page for VBA word - vba

Just a quick question. Is there a way to create a front page as a dashboard with buttons in word to assign to the macros created?
I have to paste the code in every word sheet I open each time I want to run it.
I would like to open a word sheet of my choice and the modules to be exported into that sheet each time where I can run them by aid of buttons.

Try this:
Place your Code (Modules and Userforms) into the Normal Project, if not in there already. If they are not there already then drag each Module and Userform from your current Project to the Normal Project.
Then in the Normal Project select the following:
Microsoft Word Objects > ThisDocument
The Select Document as your Object and then New as your Procedure.
Then in the Document_New Sub Call your "DashBoard" or the Macro which initialises your code and bring up the first Userform.
Private Sub Document_Open()
'When you open an Existing Word Document
MsgBox "This Worked"
Call SomeMacro
End Sub
Private Sub Document_New()
'When you open a New Word Document with Word already Open
MsgBox "This Worked"
Call SomeMacro
End Sub
Note: This will only auto run the Macro when you open a Word Document that exists already. It will not work if you open Word using the Application Button as found in the Start Menu > Programs >Microsoft Office.
EDIT:
To run a macro if the Word Application has been Executed (Started from the Microsoft Word Application Button) then have a macro in the Normal project named AutoExec.
Sub AutoExec()
MsgBox "This Messages Appears Every time"
End Sub

Related

Event handler cause problem when i force application quit

I have a macro that captures word events. In this macro in the Document_Open event, I'm going to show the dialog box and force word to quit. With the latest update, the exit instruction causes me a serious error that is shown to me when I go to recall the same document. If I delete the Word close statement and do it manually everything works fine.
I tried different solutions but could not solve the problem.
I use Word 365 .
This is the event class where i call the routine and then close the document and quit from Word.
Public WithEvents App As Application
Private Sub App_DocumentOpen(ByVal Doc As Document)
StampaModulo
Doc.Close False
App.Quit
End Sub
This is the module where in AutoExec I associate the application with the class.
Dim x As New EventClassHandler
Public Sub AutoExec()
Set x.App = Application
End Sub
When I open the same word document, the document is in the disativated element and I receive this message.
I tried also to force the quit in the routine of the print of the word document but I have the same problem.

How to create an AutoOpen macro in a Word 365 document

How do I create a macro that will run automatically each time a Word 365 document is opened? A Bing search does not seem to throw up any up-to-date answers. The Help within Word does not even recognise the word AutoOpen!
The format of an AutoOpen routine looks like this:
Sub AutoOpen()
MsgBox "This document is copyrighted."
End Sub
For more information on AutoOpen and other Auto macros see this Microsoft article.
https://learn.microsoft.com/en-us/office/vba/word/concepts/customizing-word/auto-macros
If what you want to do only effects a single document when it is opened, you can also use the following.
Private Sub Document_Open()
MsgBox "This document is copyrighted:"
End Sub
For more information on the Document.Open event see this Microsoft article. https://learn.microsoft.com/en-us/office/vba/api/word.document.open

Run macros once Word doc is opened

I'm trying to run a few macros processes once I open my word doc. Is there any way I can run all of it automatically once I open the document? Thanks.
If the macro should run when the document is opened, name the macro AutoOpen.
In order to run a macro when creating a new document from a template, name the macro AutoNew.
The information in this article might be useful.
when you create a sub with this name "Document_Open()" it will run whoever document opens.
Sub document_open()
MsgBox ("Hello")
End Sub
Under the project tab in the VBA editor I use:
Private Sub Document_open()
'insert your macros directly or call them In here
End Sub
The document will need to be saved as a macro enabled document (.docm) for this to work.

Document_New Not Working

I have created Macro Enables Templates which will execute the Document_New sub when it opens but to have something for all word documents I can seem to get it right.
I have included the following Script into the Normal Project
Microsoft Word Objects > ThisDocument
Private Sub Document_Open()
'When you open an Exisiting Word Document
MsgBox "This Worked"
Call SomeMacro
End Sub
Private Sub Document_New()
'When you open a New Word Document with Word already Open
MsgBox "This Worked"
Call SomeMacro
End Sub
Note: This will only auto run the Macro when you open a Word Document that exists already. It will not work if you open Word using the Application Button as found in the Start Menu > Programs >Microsoft Office.
I have seen people referring to Event handlers, but I am not sure what that it.
I am using Word 2010.
Want to see if there is a way for a Macro to execute if the Word.exe is run
For a macro that executes whenever Word starts up use the macro name: AutoExec. Be sure to place the macro in a "normal" module, not a class module or ThisDocument (which is also a kind of class module).

How to run automatically Excel macros?

I have created a cricket sheet in excel. I have also created a macro which is used to display a message when overs bowled are equal to 20 (A T-20 Match). My problem is that when the over get to 20 no message is shown unless I press the shortcut key. Is there anything which I can do so that whenever overs reach to 20 a message automatically displays.
My code is:
Sub Innings()
If Range("H43") = 20# Then
MsgBox "Innings Completed"
End If
End Sub
Include the following macros in the worksheet code area:
Private Sub Worksheet_Calculate()
Call Innings
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("H43")) Is Nothing Then
Call Innings
End If
End Sub
Because they are worksheet code macros, they are very easy to install and automatic to use:
right-click the tab name near the bottom of the Excel window
select View Code - this brings up a VBE window
paste the stuff in and close the VBE window
If you have any concerns, first try them on a trial worksheet.
If you save the workbook, the macros will be saved with it.
If you are using a version of Excel later then 2003, you must save
the file as .xlsm rather than .xlsx
To remove the macros:
bring up the VBE windows as above
clear the code out
close the VBE window
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!
Gary's Student's code is working well. You just need to write Worksheet_Change and Worksheet_Calculate to the List1 not to the Module1. I add a picture.