Results 1 to 5 of 5

Thread: Handling Excel dialog boxes

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244

    Handling Excel dialog boxes

    I have written an enterprise level utility whose sole purpose in life is to seek out Excel and Visio documents and alter their paper sizes based on criteria specified in a configuration file (per my customers request).

    The utility performs surprisingly well on Office XP and Office 2003. In Office XP and above, there is a method called EnableEvents (True / False) that determines whether or not macros fire. For obvious reasons, when the program is going through 10,000+ files, you do not want the macros executing.

    However, on Office 2000, this method does not exist. As a result, you cannot prevent the macros from executing. Furthermore, if you try and trick the system by raising the security level of Excel to high for macros temporarily, the macros still execute as the documents are opened programmatically and as such inherit the trust given to the application that called it. This is a bad design and I have already submitted a request to change this behavior in future versions of Office as the behavior exists to this day.

    I have been working an SRX with MS Dev's for a few weeks now on a solution to this problem and every solution we have come up with has hit one wall or another.

    So I had a new thought that I want to test, but I have never done anything like it so I need some help getting started. The one document in particular that is causing problems is a time card that has several dialog box prompts. Now, regardless of what you answer (Y, N, Cancel, etc...), as long as you navigate through them, my program continues to execute.

    What I would like to do is handle the dialog boxes and pass values to them. I have done some reading up on SendKeys, but I am unsure on how to implement them in my code.

    Keep in mind that this one particular document has 3 "y/n" / OK dialog boxes in it so I need to be able to handle multiples.

    Thank you for any assistance you can provide.

    Jim

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Handling Excel dialog boxes

    Moved from Classic VB forum.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Handling Excel dialog boxes

    Have you tried using .DisplayAerts ? It will "turn off" the msgbox's for warnings etc. but the only drawback is that it will select the default button on the alert if it was actually displayed, except in one case with the save as dialog box. The default is Yes when displayed but No when not displayed. This could make it difficult if that is one you need.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Posts
    244

    Re: Handling Excel dialog boxes

    Rob,

    The tool sets the following before opening the first Excel file.

    xlApp.DisplayAlerts = False
    xlApp.Interactive = False
    xlApp.EnableEvents = False ' Works on Office XP and above
    xlApp.Visible = False

    Here is the bug with Office 2000, there is a KB article on the topic.

    When display alerts is set to False, the first line of an embedded macro does not fire. However, the next line flips the value to true. As a result, the next dialog box / warning will be displayed without hesitation.

    We pursued the Excel Add-On route last week (myself and Microsoft) and I truly believe the only viable solution at this point is to handle the dialog boxes myself.

    Thanks,

    Jim

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Handling Excel dialog boxes

    Yes, so if your needing to dismiss the alerts then your going to have to use APIs to programmatically click the choice you want. Check out FindWindow, FindWindowEx, and SendMessage APIs.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width