我正在尝试打开Excel文件并将其数据复制到我的其他工作簿。我能够通过文件对话框打开文件。我怎么想把数据复制到Excel表格上?
Sub selectfile()
Dim strFileToOpen As String
Dim i As Integer
Dim count As Integer
strFileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to open", _
FileFilter:="Excel Files *.xls* (*.xls*),")
If strFileToOpen = False Then
MsgBox "No file selected.", vbExclamation, "Sorry!"
Exit Sub
Else
Workbooks.Open Filename:=strFileToOpen
End If
End Sub
答案 0 :(得分:0)
Option Explicit
Sub selectfile()
Dim strFileToOpen As String
Dim i As Integer
Dim count As Integer
strFileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to open", _
FileFilter:="Excel Files *.xls* (*.xls*),")
If strFileToOpen = False Then
MsgBox "No file selected.", vbExclamation, "Sorry!"
Exit Sub
Else
Workbooks.Open Filename:=strFileToOpen
'HERE
activesheet.name = "Copy Sheet"
Sheets("Copy Sheet").Range("A1:" & Sheets("Copy Sheet").SpecialCells(xlCellTypeLastCell).Address).Copy Destination:=Sheets("ENTER YOUR SHEET NAME HERE").Range("A1")
End If
End Sub