创建Excel文件及复制数据
我现在有一个Excel文件,其中有A,B,C三个Sheet。现在需要分别把A,B,C创建为名为A,B,C的三个Excel文件,每个文件只包含文件名对应的Sheet中的数据。应该怎么操作呀?
[解决办法]
Dim filePath As String
filePath = "D:\新規Microsoft Office Excel 97-2003.xls"
Dim wbk As Workbook
Set wbk = GetObject(filePath)
Dim sht As Worksheet
For Each sht In wbk.Sheets
sht.Copy
ActiveWorkbook.Close SaveChanges:=True, Filename:="D:\" & sht.Name & ".xls"
Next
wbk.Close False
Set wbk = Nothing
[解决办法]
Workbooks(g_file_name).Activate '激活原始数据工作薄
With Workbooks(g_file_name)
With Worksheets("Sheet1")
g_reported_date_befor = .Cells(1, 3).Value
g_reported_date_end = .Cells(1, 5).Value
'复制数据源
.Cells.Select
Application.CutCopyMode = False
Selection.Copy
End With
End With
ThisWorkbook.Activate '激活当前工作薄
'黏贴数据源
Sheets("数据源").Select
Sheets("数据源").Cells(1, 1).Activate
ActiveSheet.Paste