I have a macro in Powerpoint 2010 to open a new document based on a template based in a central location, to be installed on several machines.
Sub PowerpointTemplate()
Application.Presentations.Open ("file")
End Sub
Powerpoint does not save the macro. Even when setting "Macro in:" to "All open presentations", it seems to reset this selection to "Presentation 1". The macro works for the time that I have this current document open, but once I close Powerpoint and reopen it, the macro has been removed.
Is there anyway to set the macro to permanently apply to all presentations?
You need to create an Add-in and load it in order to make the code available to all open presentations.
Setting Macro In to All Open Presentations simply SHOWS you the available public macros in all open presentations; it has no effect on where the macro code is saved.
Related
Using Word 2013.
I found this previous question that is similar, but there was no accepted answer, and I'm not trying to build an add-in, so I hope I don't need something complex.
I have AutoNew and AutoOpen macros in my Normal.dotm. They are working great except that neither one of them fires when I open Word from the taskbar or other icon. In that situation, Word opens with the blank "Document1," but without the initialization I want.
Suppose my macros display a message with the document's name when a document opens or is created. I know this is silly, but it seems like a workable example.
If I open a document by clicking on it in File Explorer or by using File | Open or File | New, then the appropriate macro will fire and the message will pop up.
But if I just open Word from scratch, then no macro fires, and there is no message displaying "Document1."
I tried AutoExec to cover this situation, but when AutoExec fires, there is no active window and no document loaded yet.
Ideas?
The example cited in the question not "workable" because it makes no sense to want to show the name of an automatically generated document.
In any case, only AutoExec will fire when the Word application is started - this is by design. AutoNew does not fire when Word creates a new, default document when the application starts. (You'll also notice if you immediately open another document, without doing anything to the default document, that document is closed automatically. In a manner of speaking, this default document doesn't exist until the user takes action on it.)
What can work is to explicitly create a new document during AutoExec. This will have the effect of generating a document in place of the default document. The document will have the same name as that default document. The only different would be that this document will not close automatically when another document is opened.
When the document is created then AutoNew (and Document_New) will be triggered.
Sub AutoExec()
Documents.Add
End Sub
In Word 2016 64bits AutoOpen is triggered before AutoExec.
So if you Open a file, when AutoExec runs you can open a new file only if there is no file already opened.
As a result when you open a file you don't have another blank document opened as well.
In Word 2010 and 2013 AutoExec is triggered before AutoOpen.
So the solution cannot be applied.
But you can ask Word to close the blank file in the AutoOpen macro.
Have you tried just adding code for the Document_New() and Document_Open() events in your Normal.dot file? I just tried it with mine and however I opened the test document I got the Document_Open() to fire. The Document_New() worked as well.
Screen shot of my setup for testing. The relevant msgbox includes the name of the document.
For employees to work, I need to put some functionality into the Document_Open macro. I want to put this macro in a template (.dot) and place it on the network. Office 2007 is installed on most machines, and I'm testing on it.
I create a document, insert the macro code, save it as a template (.dot). I use the following macro code as a test:
Sub Document_Open()
MsgBox "ABC"
End Sub
Next, I create a document (.doc) and change the document template on my created template. I allow the execution of macros, the macro work. I save and close the document, when I reopen the document and enable macros, our macro does not work. What the problem is I can’t understand. Thank!
In Excel 2013, Excel likes to remember Excel windows (not worksheets) that were open, and when the workbook is opened again, also open up those windows:
From user interface: With a new workbook, Ribbon Tab "View" and then "New Window". Now two windows are open. Edit at will. Save the WorkBook. Then when that workbook is opened again, both windows are opened.
I'd like to prevent this this programatically within VBA, as part of WorkBook_Open I suppose, so that just one window would open. How can I do that? I've tried closing all windows using WorkBook_Close, that didn't work.
Just loop through the Windows collection and close them until you only have one open:
Private Sub Workbook_Open()
Do While Me.Windows.Count > 1
Me.Windows(1).Close
Loop
End Sub
I have a custom button (not an add-in, just a "shortcut" button) in Excel's quick access toolbar to run a macro in the active workbook. The workbook is modified and saved daily with a new filename. When the link is first created in the active workbook (call it Version 1) the macro runs fine. However the following day (filename now Version 2) clicking on the macro button opens workbook Version 1 and runs the macro saved in Version 1.
Is there a simple way to break the link and run the macro in the most recent active workbook?
The code is basic - it just opens up a userform and is saved in "ThisWorkbook"
Sub OPEN_DATA_USERFORM()
ufDATA.Show
End Sub
I will try to guide you through this, I hope it helps.
What we need to do is we need to call OPEN_DATA_USERFORM() from our "PERSONAL.XLSB" file. In VB editor screen, in the project explorer you will find a file called "PERSONAL.XLSB", you need to add an "Module" to that and add following code:
Sub KickOff()
Call Application.Run(Excel.ActiveWorkbook.Name & "!OPEN_DATA_USERFORM")
End Sub
By this we will be able to call the userform.show function from our PERSONAL.XLSB which is always running in the background when you open the excel.
PS: I am assuming your OPEN_DATA_USERFORM() is coded in your daily workbook.
UPDATE: PERSONAL.XLSB
Your file should be visible in your project explorer like below:
If it is not there record a dummy macro and select your personal file like below then it should appear in your project explorer in VBA screen:
My colleagues and I have created a userform with a suite of tools for doing tasks in Excel and Word
I'm quite familiar with spawning application objects from modules and closing them without effecting anything else - or other running copies of Excel.
However the user form must start some where - this leaves an Excel sheet open in the background.
I have tried Application.Visible = False but this hides all open workbooks - Kind of annoying if you have other worksheets open
I was thinking of a wrapper sheet which creates an Excel and runs the macro (spawning the macro in its own instance of Excel) - this works but then Im left with the wrapper sheet and potentially an orphan excel app if I close my parent.
Is there a better way than this to execute macros without affecting the rest of the user experience on MS office?
Yes, you can create an Excel add-in. Simply save the Workbook containing your code as an Excel add-in (select the appropriate file format in the "Save As" dialog) and configure Excel to load the add-in at startup in the "Options". You won't see anything of the add-in besides the functionality it provides.