VBA和PowerShell集成?

我试图创build一个macros,当数据input到单元格区域时,它将触发一个PowerShell脚本。 在这个PowerShell脚本中,我试图从我的PowerShell查询中获取对象,以返回到活动工作表,macros被触发。 唯一困难的部分是,工作簿位于SharePoint服务器上。

有没有人有任何洞察力如何实现我的目标,或任何链接帮助指向正确的方向。

谢谢。

您将需要更改事件,以便您可以处理单元格中的数据何时发生更改的检查。

其次,你需要一个从powershell命令返回数据的方法。 我只是使用命令行操作中的>>操作符将数据放入文本文件中,然后再读取文本文件。

第三,你需要对这些数据做些什么。

Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$A$1" Then ' If A1 changes... Dim FileNum As Integer Dim FileName As String Dim DataLine As String Dim objShell Dim fso Set fso = CreateObject("Scripting.FileSystemObject") Set objShell = CreateObject("WScript.Shell") FileName = "C:\data.txt" cmdString = "Powershell DIR >>" + FileName ' Cmd String for Powershell Call objShell.Run(cmdString, 0, True) ' Run the command, data is exported to FileName path FileNum = FreeFile() Open FileName For Input As #FileNum ' Open the File we generated While Not EOF(FileNum) Line Input #FileNum, DataLine ' read in data 1 line at a time ' Do something with data line that was saved from the shell script. Wend Close #FileNum Call fso.DeleteFile(FileName) ' Delete the file we generated End If End Sub