Something IS wrong concerning macros in the "Security center ..." !

KeldSor 391 Reputation points
2023-06-29T09:59:30.91+00:00

I have made some VBA-code for running only once to correct a FileName fields in the Footer of a lot of Word documents I have stored in a folder hieraki.

Traversing the hieraki IS working nicely and hands me a File object.

That file object I process with this snip of code:

Sub handleFile(Doc As Object)
    
'    Debug.Print Doc.path
'    Exit Sub

    Dim appWrd As New Word.Application
    Set Doc = appWrd.Documents.Open(Doc.Path)    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< (A)
    InsertAndUpdateFieldsInFooter Doc
    Doc.Save
    Set Doc = Nothing
    appWrd.Quit
    Set appWrd = Nothing
End Sub

The line marked (A) shows a msgbox that the macros in that doc.path is DIABLED and I have to manually click OK button continue - this invalidates the purpose of my "run-one-time-macro" !

On the other hand if I do click the OK button it all works as I want it to and my footer IS corrected as planned !

To get rid of that "manually clicking OK" I correct the settings in the "Security center ..." and allow all macros to be enabled eventhough it's not recommended - then run again ... but another message comes up:

billede

Again I have to manually click the button (Without macros) ... but for a strange filename not known to me !

The app works again but it ends up in a completely mess around nor been able to save the NORMAL.DOTM !

How should these stupid checkmark be set in the "Security center... " for me to run my macro ONE TIME only ?

Microsoft 365 and Office | Development | Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. John Korchok 226.2K Reputation points Volunteer Moderator
    2023-06-29T14:46:05.68+00:00

    Microsoft has recently tightened up macro security, so you situation is fairly common now. Try setting the location of the macro-enabled document as a Trusted Location in the Trust Center settings. If the location is on a network drive, you should use the server name, not an IP address in the Trusted Location setting.


  2. KeldSor 391 Reputation points
    2023-07-08T07:49:23.6433333+00:00

    SOLVED - the code CAN NOT be run from the Normal.dotm without these problems !

    I moved the exact same code to a module in Access - and it run without any problems at all !

    I see NO reason why !

    0 comments No comments

  3. John Korchok 226.2K Reputation points Volunteer Moderator
    2023-07-08T15:31:25.1666667+00:00

    If you're running the macro in Word, there's no need to be using OLE to start a new Word application. You might have better luck if you simplify your code.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.