启动excel时运行batch file

我有一个问题:有没有办法,当用户双击Excel文件,批处理或cmd文件将启动,这将启动单击的Excel文件? 我们希望进一步保存员工在电脑上使用文件的频率。
我需要使用batch file或cmd文件,因为excel文件在其他计算机上,我们将使用组策略来并入脚本

你可以使用VBA来做到这一点。 在VBA项目的“ThisWorkbook”部分,你可以添加类似的东西

 Option Explicit Private Sub Workbook_Open() Dim strPath As String 'put the location and name of your batch file here strPath = "C:\YourFolder\YourBatchFile.bat" Call Shell(strPath) End Sub 

如果您不确定使用VBA代码,请参阅此链接

 Set WshShell = WScript.CreateObject("WScript.Shell") Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2") Set objEvents = objWMIService.ExecNotificationQuery _ ("SELECT * FROM Win32_ProcessStopTrace") Do Set objReceivedEvent = objEvents.NextEvent msgbox objReceivedEvent.ProcessName If lcase(objReceivedEvent.ProcessName) = lcase("Notepad.exe") then Msgbox "Process exited with exit code " & objReceivedEvent.ExitStatus WshShell.Run "c:\Windows\notepad.exe", 1, false End If Loop 

这是一个监视所有程序停止的vbs脚本。 您可以使用Win32_ProcessStopTrace,Win32_ProcessStartStopTrace或Win32_ProcessStartTrace。

这是为了replace一个batch file。 写一个日志

 Set Fso = CreateObject("Scripting.FileSystemObject") Set File = Fso.CreateTextFile("c:\folder\filename", True) file.writeline "text"