如何searchclosures的excel文件

我试图search一个closures的excel文件进​​行匹配,然后将相对于该匹配的引用转换为一个string,然后将该string放入打开的word文档,然后重复,直到find所有匹配。 我完全坚持打开Excel文件来访问它来search开始虽然。

它会在任务pipe理器中生成一个excel进程,但是我无法引用它,我实际上期望它打开该应用程序。 我可能会完全错误的。

Sub stringPrompt2() 'Find match 'build output 'put into word doc 'repeat Dim sSearchString As String Dim sSearchDirectory As String Dim dlgFile As FileDialog Dim vSelectedItem As Variant Dim Loc As Excel.Range Dim sPath As String sSearchString = InputBox("String to search for", vbOKOnly, "Search String") Set vSelectedItem = Application.FileDialog(filedialogtype:=msoFileDialogFilePicker) With vSelectedItem .AllowMultiSelect = False .Show End With sPath = vSelectedItem.SelectedItems.Item(1) Workbooks.Open sPath ' it isn't launching excel here. End Sub 

您只需创build一个variables来保存工作簿引用,并将Workbooks.Open命令的结果分配给该variables,以便您可以使用它:

 Dim myWorkbook As Workbook Set myWorkbook = Workbooks.Open sPath ' Then do whatever you want with the Workbook object MsgBox(myWorkbook.Name)