タイトル | : Re^3: RECORDCOUNTについて |
記事No | : 15890 |
投稿日 | : 2014/04/17(Thu) 19:56 |
投稿者 | : YK |
こんにちは。 シートコピーしなくていいですね。 こんな感じで
Sub testA() Dim DB As DAO.Database Dim rs As DAO.Recordset Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Dim xlFileName As String Dim xlSheetName As String Dim xlSht As Excel.Worksheet Dim clm As Long Dim row As Long Dim sA As String 'Excelを表示 Set xlApp = New Excel.Application xlApp.Visible = True xlFileName = "D:\Excel\TEST11\DAO_test.xls" 'Excelファイル名 xlSheetName = "Sheet1" 'Excelシート名 Set xlBook = xlApp.Workbooks.Open(xlFileName) Set xlSht = xlBook.Worksheets(xlSheetName) With xlSht clm = .Cells(1, .Columns.Count).End(xlToLeft).Column row = .Range("A" & .Rows.Count).End(xlUp).row sA = "$" & .Range(.Cells(1, 1), .Cells(row, clm)).Address(False, False) End With Set DB = OpenDatabase(xlFileName, False, False, "Excel 8.0;HDR=YES;IMEX=1") Set rs = DB.OpenRecordset(xlSht.Name & sA, , dbOpenTable) 'dbOpenDynaset ,dbOpenSnapshot Debug.Print "件数="; rs.RecordCount xlApp.Quit rs.Close DB.Close End Sub
|