Excel I';我正试图将一个“.txt文件”从另一个工作簿导入到工作簿中,但没有';行不通

Excel I';我正试图将一个“.txt文件”从另一个工作簿导入到工作簿中,但没有';行不通,excel,vba,Excel,Vba,假设我正在处理工作簿A,工作簿A生成一个.txt文件。 我还有工作簿B,其中包含一个表,可以从.txt文件接收数据。 我想将工作簿A生成的.txt文件导入到工作簿B中,我想用工作簿A这样做 这是我的密码: Sub result_template() Dim FL As String Dim wb As Workbook Dim restemplate As Object With Application.FileDialog(msoFileDialogFilePicker)

假设我正在处理工作簿A,工作簿A生成一个
.txt文件
。 我还有工作簿B,其中包含一个表,可以从
.txt文件
接收数据。 我想将工作簿A生成的
.txt文件
导入到工作簿B中,我想用工作簿A这样做 这是我的密码:

Sub result_template()

Dim FL As String
Dim wb As Workbook
Dim restemplate As Object

        With Application.FileDialog(msoFileDialogFilePicker)   '
            .Title = "Select the log file"                 'Open the file explorer
            .InitialFileName = ThisWorkbook.path & "\"         'for you to select
            .InitialView = msoFileDialogViewDetails            'the file you want
            .AllowMultiSelect = False                          'to format
            .Show

            If Not .SelectedItems(1) = vbNullString Then Sheets(5).Cells(36, 16).Value = .SelectedItems(1)

        End With

        With Application.FileDialog(msoFileDialogFilePicker)   '
            .Title = "Select the result template"              'Open the file explorer
            .InitialFileName = ThisWorkbook.path & "\"         'for you to select
            .InitialView = msoFileDialogViewDetails            'the file you want
            .AllowMultiSelect = False                          'to format
            .Show

            If Not .SelectedItems(1) = vbNullString Then FL = .SelectedItems(1)
            Set restemplate = wb.OpenText(FL, 3, xlDelimited, True, True)

        'Code to copy the contents of the .txt file to your table

            ActiveWorkbook.Close Savechanges:=True filename:="result" & Date


        End With

End Sub
我在
ActiveWorkbook上出现语法错误。请关闭

并且在
set restemplate=wb.OpenText(FL,3,xlDelimited,True,True)


我做错了什么?

您在
文件名:=
之前缺少了一个逗号,您可能需要
格式化日期,而不仅仅是
&date
。然后,
Workbooks.OpenText
不会返回任何内容,因此您无法执行
Set restemplate=…
在哪里可以找到有关如何使Workbooks.OpenText返回内容的更多信息?有些事我不明白,但不知道是什么!它不会返回任何内容,也永远不会返回任何内容-在这种情况下,您需要在
Workbooks.OpenText
之后立即使用
ActiveWorkbook