Disable all dialog boxes in Excel while running VBscript?

后端 未结 5 1549
旧巷少年郎
旧巷少年郎 2021-01-04 01:19

I have some code in VB that saves all XLSM files as XLSX. I already have the code that will do that for me, but dialog boxes show up for every action. This was fine for a fe

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-04 02:04

    Solution: Automation Macros

    It sounds like you would benefit from using an automation utility. If you were using a windows PC I would recommend AutoHotkey. I haven't used automation utilities on a Mac, but this Ask Different post has several suggestions, though none appear to be free.

    This is not a VBA solution. These macros run outside of Excel and can interact with programs using keyboard strokes, mouse movements and clicks.

    Basically you record or write a simple automation macro that waits for the Excel "Save As" dialogue box to become active, hits enter/return to complete the save action and then waits for the "Save As" window to close. You can set it to run in a continuous loop until you manually end the macro.

    Here's a simple version of a Windows AutoHotkey script that would accomplish what you are attempting to do on a Mac. It should give you an idea of the logic involved.

    Example Automation Macro: AutoHotkey

    ; ' Infinite loop.  End the macro by closing the program from the Windows taskbar.
    Loop {
    
        ; ' Wait for ANY "Save As" dialogue box in any program.
        ; ' BE CAREFUL!
        ; '  Ignore the "Confirm Save As" dialogue if attempt is made
        ; '  to overwrite an existing file.
        WinWait, Save As,,, Confirm Save As
        IfWinNotActive, Save As,,, Confirm Save As
            WinActivate, Save As,,, Confirm Save As
        WinWaitActive, Save As,,, Confirm Save As
    
        sleep, 250 ; ' 0.25 second delay
        Send, {ENTER} ; ' Save the Excel file.
    
        ; ' Wait for the "Save As" dialogue box to close.
        WinWaitClose, Save As,,, Confirm Save As
    }
    

提交回复
热议问题