Running VBA through Access
I have 7 select queries in an access database that I will be doing TransferSpreadsheet with that all go on the same Excel sheet.
Currently I am just attempting to set a variable with the next empty cell with a start point of A23.
In my attempt to locate the next empty cell I continue to get run-time error 1004.
I've inserted PATH for fpath variable for confidentiality.
Error is occurring when I try to set the n1 variable. If I comment out setting the n1 variable then the error occurs on the MsgBox....
Private Sub Command0_Click()
Dim n1 As String
Dim n2 As String
Dim n3 As String
Dim n4 As String
Dim n5 As String
Dim n6 As String
Dim n7 As String
Dim start As String
Dim fpath As String
Dim strFileExists
Dim xlapp As Excel.Application
Dim xlbook As Excel.Workbook
Dim xlsheet As Excel.Worksheet
Dim xldata As Excel.Range
'Set start cell on the CAECAN file
start = "A23"
fpath = "PATH"
strFileExists = Dir(fpath)
If strFileExists <> "" Then
Set xlapp = CreateObject("Excel.Application")
Set xlbook = xlapp.Workbooks.Open(fpath)
Set xlsheet = xlbook.Worksheets("Audit Remittance CAD invoices")
With xlapp
.Visible = False
.DisplayAlerts = False
.Workbooks.Open fpath
With xlsheet
n1 = Range(start).End(xlDown).Offset(1).Select
MsgBox "The first empty cell in column A is: " & Range(start).End(xlDown).Offset(1).Address
End With
End With
Else
MsgBox "File does not exist"
End If