Sub vbaTest()
\'数据读取
\'----------------------------------------------
Dim dataExcel, Workbook, sheet
Dim totalRow As Integer
Set dataExcel = CreateObject("Excel.Application")
Set Workbook = dataExcel.Workbooks.Open(ThisWorkbook.Path & "\finall.xls")
Set sheet = Workbook.Worksheets(1) \'读取第一个sheet页的数据
\'totalRow = ActiveSheet.Range("C" & Rows.Count).End(xlUp).Row
\'totalRow = 100
totalRow = sheet.UsedRange.Rows.Count
totalColumn = sheet.UsedRange.Columns.Count
For i = 1 To totalRow
For j = 1 To totalColumn
Sheets("sheet1").Cells(i, j) = sheet.Cells(i, j)
Next j
Next i
Workbook.Close
MsgBox "读取成功!", vbSystemModal \'读取完后弹框提醒
\'----------------------------------------------
End Sub


Option Explicit
Sub main()
Dim wb As Workbook
\'Application.DisplayAlerts = False
Set wb = Workbooks.Open("D:\Python\downtest\data.xls")
wb.Sheets(1).Columns("A").ColumnWidth = 10
Windows(wb.Name).Visible = True
wb.Close savechanges:=True
\'Application.DisplayAlerts = True
Set wb = Nothing
End Sub
Sub 打开选择文件()
Dim file As String
Dim wk As Workbook
file = Application.GetOpenFilename
Set wk = GetObject(file)
wk.Sheets(2).Columns("A").ColumnWidth = 10
Windows(wk.Name).Visible = True
wk.Close savechanges:=True
Set wk = Nothing
End Sub
View Code