如何把两个文件表格用VBA从另一个EXCEL表格导入数据到这个表格中?

RT
2024-12-18 05:39:06
推荐回答(5个)
回答1:

能写成这样,喊嫌缺还有什么完不成?

部分代码:

Dim xlsheet As Excel.Worksheet

Dim xlbook As Excel.Workbook

ll = ListBox1.ListIndex

Set xlbook = ThisWorkbook.Application.Workbooks.Add(ListBox1.List(ll))

Set xlsheet = xlbook.Worksheets(1)

T11.Text = xlsheet.Range(T1.Text)

xlbook.Close SaveChanges:=False

xlsheet.Copy ThisWorkbook.Sheets(1)

xlbook.Close 者哗SaveChanges:=False

若郑辩不明白之处,可联系848555411@qq.com

回答2:

Sub 导入数据稿笑弊()
Dim Wb As Workbook
Dim Temp As String
Application.ScreenUpdating = False
Temp = ThisWorkbook.Path & "\aaaaaaa.xls" '这个是你要键族导入的表文件路径
Set Wb = GetObject(Temp)
With Wb.Sheets("升轿sheet1").Range("A2").CurrentRegion
Range("A2").Resize(.Rows.Count, .Columns.Count) = .Value
Wb.Close False
End With
Set Wb = Nothing
Application.ScreenUpdating = True
End Sub

回答3:

Sub 合并工作簿()
Dim FilesToOpen
Dim x As Integer

On Error GoTo ErrHandler
Application.ScreenUpdating = False

FilesToOpen = Application.GetOpenFilename _
(FileFilter:="Microsoft Excel Files (*.xls), *.xls", _
MultiSelect:=True, Title:="Files to Merge")

If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
GoTo ExitHandler
End If

x = 1
While x <= UBound(FilesToOpen)
Workbooks.Open Filename:=FilesToOpen(x)
Sheets().Move After:=ThisWorkbook.Sheets _
(ThisWorkbook.Sheets.Count)
x = x + 1
Wend

ExitHandler:
Application.ScreenUpdating = True
Exit Sub

ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub

回答4:

未说明清楚。两个表格是怎样表格?是相同表格(复制粘贴即可)?还是总分关系,最好能附上附件。

回答5:

VBA很容易实现