VBA执行打开
- Sub test()
- Dim File As Workbook
- Dim cnn
- Dim SQL$
- Dim Path, Text1, SheetName As String
- Path = ThisWorkbook.Path & ""
- Text1 = "test.xlsx"
- SheetName = "Sheet1"
- With Sheets("Sheet1")
- .[A:E].ClearContents
- Set File = Workbooks.Open(Filename:=Path & Text1, Password:="123")
- Set cnn = CreateObject("adodb.connection") 'Create DB Connection
- cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0;extended properties=Excel 12.0;Data Source=" & Path & Text1
- SQL = "select [Loan No#] from [" & SheetName & "$A:DH]"
- .[A65536].End(xlUp).Offset(1, 0).CopyFromRecordset cnn.Execute(SQL)
- cnn.Close 'Close SQL Connection
- Set cnn = Nothing 'Clean SQL from RAM
- File.Close True
- End With
- End Sub
[color=rgb(51, 102, 153) !important]复制代码 |