none
Excel Enables Makros when reading VBProject Infos RRS feed

  • Question

  • Hi Forum,

    i'm writing an Excel VSTO Addin, handling some feautures for our internal workbbooks and showing some Infos for the ActiveWorkbook.

    The Problem: When the user opens a Workbook and i read the VBProject Informations the Excel Question "enable Makros" disappear and the Makros are enabled then.

    1.: I don't want to automatically enable the Makros of every Workbbok.

    2.: After that the most Makros works when starting from the VBA Editor but Clicking on a Buttons brings (sometimes) the Message, that the Makro could'nt be found. So sometimes they are enabled sometimes they are "half enabled".

    So: Is there a way to Check from an Addin if Excel is showing the questeion "enable Makros"? Then i could exit and try it again, when the user activates the Makros by himself (WorkbbokChange() fires again then).

    I couldn't find a way, reading of any VBProject propertie enables the Makros automatically. This happens in Excel 2010, 2013 and 2016.

    Many thanks for each tip ;)

    best regards

    K.



    • Edited by K_G__ Thursday, November 30, 2017 1:29 PM
    Thursday, November 30, 2017 1:28 PM

All replies

  • Hi K.

    >>I couldn't find a way, reading of any VBProject propertie enables the Makros automatically. 

    You could go to File->Options->Trust Center->Trust Center Setting->Macro Setting to choose the Macro Setting. To enable macros automatically, you could select "Enable all macros (not recommended, potentially dangerous code can run)".

     >>Clicking on a Buttons brings (sometimes) the Message, that the Makro could'nt be found.

    Please check if the assigned macro is removed or re-named.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, December 1, 2017 2:46 AM
  • Hi,

    please see above : 1.: I don't want to automatically enable the Makros of every Workbbok.

    The solution of course should not be, that the user enables all Makros automatically by himself ;)

    2. The Makros did exist. And mostly the Button Klick works. When Start a File 10 Times 7 Times i can Click the Buttons and three Times i get hte Message that the Makros coud not be found.

    best Regards.

    Monday, December 4, 2017 8:03 AM
  • Hi K_G_,

    >>When the user opens a Workbook and i read the VBProject Informations....

    Do you read VBProject information in VSTO? If you do not read the information, will the Question disappear? Have you ever checked the checkbox "Trust access to the VBA project object mode" in my previous screenshot? If not, I would suggest you check the checkbox and test again.

    >>When Start a File 10 Times 7 Times i can Click the Buttons and three Times i get hte Message that the Makros coud not be found

    Please share a simply workbook and detail your reproduce steps so we could try to reproduce your issue. You could share the file via Cloud Storage, such as One Drive, and the put link address here.

    Thanks for understanding.

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 5, 2017 8:33 AM
  • Hi K,

    >> Is there a way to Check from an Addin if Excel is showing the questeion "enable Makros"?

    From Excel object mode, it is impossible.

    For a workaround, I think you could check the Macro settings registry keys from AddIn.

    For registry location, it is HKEY_CURRENT_USER\software\policies\microsoft\office\15.0\excel\security.

    # Microsoft Project – how to control Macro Settings using registry keys

    https://blogs.technet.microsoft.com/diana_tudor/2014/12/02/microsoft-project-how-to-control-macro-settings-using-registry-keys/

    If you have any issue to retrieve registry keys from AddIn, please feel free to post a new thread.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, December 5, 2017 8:36 AM
  • Hi and thanks for the replys until now.

    Maybe my English is to bad, sorry for that.

    Trust Access to the VBA Project is checked and i've no problem to read VBA-Project infos

    Disable all Makros with notification is checked and that's it what we want: The user should decide to enable Macros or not.

    The Problem: When i read any information about the VBA-Project out of my com-addin the "enable Makro" Button disappears and the Makros get enabled. The reading of the VBA-Project informations is no Problem, i get the informations but the user could not decide to disable the Makros in this Workbook at this Moment and sometimes Excel disables Buttons on Sheets.

    So the Information from the Registry doesen't help. I need to stop, when the Makros of the Workbook Change Event in the Addin (at this Moment opend workbook) are not enabled at this moment by the user.

    Whe a user enables the Makros of one Workbook one time then the next time (same workbook) Excel didn't ask and all things work perfect. Renaming the Workbook brings the Question "enabe Makros?" back and this good.

    I can't and i wouldn't enable all Makros automatically (what about viruses?) the user has to decide for every new Workbook.

    So how read VBA-Project Information without enabling Makros from an addin OR

    How to check that the "enable Makros?" Button is shown and don't read then?

    To Check this Problem:

    Create a VSTO-Addin and copy this sub in "ThisAddIn":

        Private Sub Application_WorkbookActivate(Wb As Workbook) Handles Application.WorkbookActivate
            Dim activeWb As Excel.Workbook = Globals.ThisAddIn.Application.ActiveWorkbook '=wb should work also
            MsgBox(activeWb.VBProject.Description) '->  "Enable Makros?" disappears and Makros are enabled (mostly)
        End Sub

    best regards.






    • Edited by K_G__ Tuesday, December 5, 2017 10:24 AM
    Tuesday, December 5, 2017 10:21 AM