将Excel工作表导入活动工作表

我有很多数据的发票。 我想导出和导入数据。 我创build了导出特定工作表(“发票数据”)的导出VBA。 我把它保存在某个地方。 现在我需要将相同的文件导入到活动工作表中。

我有这个代码

Dim WB As Workbook Dim SourceWB As Workbook Dim WS As Worksheet Dim ASheet As Worksheet 'Turns off screenupdating and events: Application.ScreenUpdating = False Application.EnableEvents = False 'Sets the variables: Set WB = ActiveWorkbook Set ASheet = ActiveSheet Set SourceWB = Workbooks.Open(WB.Path & "\1.xlsx") 'Modify to match 'Copies each sheet of the SourceWB to the end of original wb: For Each WS In SourceWB.Worksheets WS.Copy after:=WB.Sheets(WB.Sheets.Count) Next WS SourceWB.Close savechanges:=False Set WS = Nothing Set SourceWB = Nothing WB.Activate ASheet.Select Set ASheet = Nothing Set WB = Nothing Application.EnableEvents = True 

这个代码工作得很好。 但我想select与文件打开对话框的文件

任何人都请帮助我

终于find代码….

 Dim wbk1 As Workbook, wbk2 As Workbook fileStr = Application.GetOpenFilename() Set wbk1 = ActiveWorkbook Set wbk2 = Workbooks.Add(fileStr) wbk2.Sheets("invoice data").Copy After:=wbk1.Sheets(1) 

感谢你们

如果你的问题是关于..如何使用文件打开对话框..你可以使用这个代码

  NewWorkbook = Application.GetOpenFilename( _ FileFilter:="Excel 2003 (*.xls),*.xls,Excel 2007 (*.xlsx),*.xlsx,Excel 2007 (*.xlsm),*.xlsm", _ Title:="Select an Excel File", _ MultiSelect:=File) If NewWorkbook = False Then Exit Sub Else Workbooks.Open Filename:=NewWorkbook End If 

如果你想select任何types的文件,你可以删除filter