Word 2010 VBA to mark document as not edited - vba

I have a Word 2010 macro that updates fields in the document when it is opened - LASTSAVEDBY, FILENAME and DATESAVED. This is the macro recommended by Microsoft in their knowledgebase article The FILENAME field does not automatically update when you open a document in Word
That works great, however when the document is opened and later closed, it always prompts to save changes, whether changes have been made or not.
Is there any code I can add to the macro that immediately marks the document as not edited, so that the prompt to save only appears when further edits are made?
Otherwise, every time someone reads a document, they will probably end up saving it with their details rather than the person who really last edited it.

Use the Document.Saved Property. For example in VBA: ActiveDocument.saved = true

Related

VBA Word. Open document problem when i re-open the sam document

some years ago i writed a VBA macro that handle the Word events (as the open document), and after some operation it close the word document and quit. My customers used the macro correctly until the last update of Word. The problem is if I try to re-open the document, Word give me the message that the docuemnt had a crash error and ask if i want to repair it. I had view that the document, after i quit Word application, is in the list of the disactivated elements. If i search in the application log of Win I can't find crash of Word. There is a way for know the reason of this behavior?
disabled elements
re-open document
I checked that the macro does not go into error. I put messages up to Auto_exit and the macro runs fine.

Word VBA AutoNew macro not firing when opening Word

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.

How to call a VBA-macro in another MS Word document?

in MS Excel I have been distributing a xls-file that contains a macro. From the users "random" current open workbook I have successfully been calling this macro by telling Word in which file to look for it. Like this, when the user clicks a button on the ribbon:
C:\\"'MyExcelFileWithTheMacro.xls'!MyMacroName"
Can I do the same in MS Word?
That is, to call a macro in a Word-file located in any given folder from an instance of Word that has not opened that file?
I have tried, of course, but Word keeps saying it can't find the macro.
The reason I want to do it this way is that it is makes for easy distribution and updating of the macro. Next up is signing the macro. I hope it can be done when doing things this way, but not sure.
No, it's not possible to call and run a macro in any Office application if the file that contains the macro is not loaded in the application interface.
That being said, if you place the macro in a *.dotm template and have the user put the template in the STARTUP folder used by the Word application, then Word will load the template as an "Add-in". And in that case you should be able to access the macro.
Or, if you don't want it in the Startup folder and you have code that automates the Word.Application, anyway, then that code can load the *.dotm as an "Addin", which should make the macro available (and remove it when you're done with it). Research Application.Addins.Load and Addin.Installed in the Word language reference as well as on-line for examples.

Exporting a picture or snapshot of a form to Powerpoint from Access 2010

I want to be able to create a loop in Access VBA that basically opens up my form based on a parameter, takes a picture or copies the form somehow and then pastes that image into a Powerpoint deck. The loop would then close the form, get the next parameter to open the same form with new data and do the same operation on the next slide of the Powerpoint deck.
I've googled this and cannot find anything that works for me. Thanks!
REVISION:
Since this seems to be a challenge to accomplish directly within Access, let me ask it another way. I've tried to output the form to a PDF file through VBA
DoCmd.OutputTo acOutputForm, "MYFORM", acFormatPDF, "MYPATH & MYFILENAME"
When I do this in a loop I only get the very last form that opens, as if when Access is sending each form to the PDF file it is overwriting the last one each time. The other problem is that I need to output the form in landscape and I'm not sure how get this to happen in the PDF file. Are there any settings that go with this method or code that would precede or follow it that would allow me to accomplish this? This is alternative because I can then just manually convert the PDF to Powerpoint if I need to.

Using Word automation, is it possible to find out if the active document contains VBA code?

Using Word Automation, I want to save the active document programmatically. In Office 2007/2010, the document needs to be saved explicitly as "macro enabled" to preserve any VBA code in that document.
Rather than asking the user to choose, I would like my application to be able to determine if there is VBA code in the active document. Is that possible?
Yes this can be determined via the HasVBProject property. For example:
If ActiveDocument.HasVBProject = True Then
'Code to save as .dotm
Else
'Code to save as .dotx
End If
For those who might stumble upon this post later, it is worth noting that this code should be placed outside the document being tested for the presence of macros (otherwise it would detect itself). Two often-used options would be to access the code from an external application or from a template stored in Word's Startup folder.