Find then save and close all open Excel documents

后端 未结 2 1230
不思量自难忘°
不思量自难忘° 2020-12-21 11:47

I need help creating a PowerShell script that will find all open Excel documents, then first if the document is read only close the document without saving and suppress prom

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-21 12:50

    Set xlBook = GetObject("C:\Users\David Candy\Documents\Super.xls", "Excel.Application")
    For each wsheet in xlbook.worksheets
        msgbox wsheet.name
    next
    

    VBScript, JScript, PS, VBA can all do it. Above is VBScript (and thus also VBA). The technology is COM not a language.

    EDIT

    As said using the app object doesn't work in excel.

    A excel file opened.

    EXCEL.EXE                    13560 Console                    1     19,228 K Running         DESKTOP-UCDGI39\David Candy
                                 0:00:00 Microsoft Excel - Super.xls
    

    Running GetObject using Excel.Application

    EXCEL.EXE                    13560 Console                    1     19,236 K Running         DESKTOP-UCDGI39\David Candy
                                 0:00:00 Microsoft Excel - Super.xls
    EXCEL.EXE                    15124 Console                    1     12,772 K Running         DESKTOP-UCDGI39\David Candy
                                 0:00:00 N/A
    

    NOTE

    • Separate process
    • Not started with COM switches (/a or /automation and /embedding)
    • No access to the other excel

    This is in addition to other faulty behaviour by excel where it won't exit memory when references are released.

提交回复
热议问题