使用 vbscript 我希望能够创建一个 excel 对象,允许用户打开文件,然后在保存文件后,能够验证文件中的数据。我尝试使用 WaitForChangedResult 来观察文件所在的目录并等待它在继续之前更改,但是它仅在文件关闭而不保存时才继续,而不是在保存时。这是该代码的样子:
Dim xl As Object
xl = CreateObject("excel.application")
xl.FileDialog(1).AllowMultiSelect = False
xl.FileDialog(1).Title = "Navigate to 60-40 loan calculator"
Dim strFilePathAndName As String
If xl.FileDialog(1).Show() = -1 Then
strFilePathAndName = xl.FileDialog(3).SelectedItems(1)
Else
Exit Sub
End If
xl.Visible = True
xl.Workbooks.Open(strFilePathAndName)
Dim strXLTab As String
strXLTab = xl.ActiveSheet.Name
Dim result As System.IO.WaitForChangedResult
Dim directory As String
directory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim watcher As New System.IO.FileSystemWatcher(directory, "Calculator.xls")
result = watcher.WaitForChanged(System.IO.WatcherChangeTypes.Changed)
TextBox1.Text = directory
有没有更好的方法来做到这一点?