Vba 如何搜索已关闭的excel文件
我试图在一个关闭的excel文件中搜索匹配项,然后将与该匹配项相关的引用提取到一个字符串中,该字符串将进入打开的word文档,然后重复,直到找到所有匹配项。我完全被困在打开excel文件访问它开始搜索的过程中 它在TaskManager中生成了一个excel流程,但我无法引用它,实际上我希望它能够打开应用程序。我可能完全走错了方向Vba 如何搜索已关闭的excel文件,vba,excel,ms-word,Vba,Excel,Ms Word,我试图在一个关闭的excel文件中搜索匹配项,然后将与该匹配项相关的引用提取到一个字符串中,该字符串将进入打开的word文档,然后重复,直到找到所有匹配项。我完全被困在打开excel文件访问它开始搜索的过程中 它在TaskManager中生成了一个excel流程,但我无法引用它,实际上我希望它能够打开应用程序。我可能完全走错了方向 Sub stringPrompt2() 'Find match 'build output 'put into word doc 'repeat Dim sSe
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
您只需要创建一个变量来保存工作簿引用,并分配工作簿的结果。对该变量执行Open命令,以便您可以使用它:
Dim myWorkbook As Workbook
Set myWorkbook = Workbooks.Open sPath
' Then do whatever you want with the Workbook object
MsgBox(myWorkbook.Name)
您只需要创建一个变量来保存工作簿引用,并分配工作簿的结果。对该变量执行Open命令,以便您可以使用它:
Dim myWorkbook As Workbook
Set myWorkbook = Workbooks.Open sPath
' Then do whatever you want with the Workbook object
MsgBox(myWorkbook.Name)