0
我的代碼從MS Access表單中獲取字段並將數據複製到已保存的Excel文件中。導入到Excel中的Access中的第一條記錄的範圍爲A2:I2。 Access中的第二條記錄導入到Excel中,範圍爲A3:I3,等等....現在發生的事情是,如果我在Access中關閉表單並將其打開並說已導入兩條記錄到這個相同的Excel文件中,現在我想添加第三條記錄,它將在第一行(A2:I2)處重新開始,並且寫下已經存在的內容。我的問題是,如果我關閉並打開Access讓它不能重新開始(A2:I2),而是從下一個可用的行開始,那麼遵循給出的示例將是(A4:I4)?這是我的代碼有將數據從MS Access表單複製到Excel中
Private Sub Command73_Click()
Set objXLApp = CreateObject("Excel.Application")
Set objXLBook = objXLApp.Workbooks.Open("Y:\123files\Edmond\Hotel Reservation Daily.xls")
objXLApp.Application.Visible = True
With objXLBook.ActiveSheet
Set r = .usedRange
i = r.Rows.Count + 1
.Cells(i + 1, 1).Value = Me.GuestFirstName & " " & GuestLastName
.Cells(i + 1, 2).Value = Me.PhoneNumber
.Cells(i + 1, 3).Value = Me.cboCheckInDate
.Cells(i + 1, 4).Value = Me.cboCheckOutDate
.Cells(i + 1, 5).Value = Me.GuestNo
.Cells(i + 1, 6).Value = Me.RoomType
.Cells(i + 1, 7).Value = Me.RoomNumber
.Cells(i + 1, 8).Value = Date
.Cells(i + 1, 9).Value = Me.Employee
End With
Set r = Nothing
Set objXLBook = Nothing
Set objXLApp = Nothing
End Sub
@Remou。我是否需要將r聲明爲對象? – Edmond 2011-02-18 16:04:05