Hello,
I am trying to create a VB code that will help automate sales Orders, however I am receiving Error #91 when I am trying to compile the code. I was wondering if someone could provide me with assistance. Here is the portion of the code that is erroring out at the line 'Set rngStart = wks.Range("A4")':
Set appExcel = GetObject(, "Excel.Application")
'Set reference to worksheet and activate it
Set bks = appExcel.Workbooks
'Create and open new, blank workbook
bks.Add
'Make the worksheet visible
appExcel.Application.Visible = True
'Set reference to query
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("qryOrders", dbOpenDynaset)
rst.MoveLast
rst.MoveFirst
lngCount = rst.RecordCount
If lngCount = 0 Then
MsgBox "No contacts to export"
GoTo ErrorHandlerExit
Else
strPrompt = "Exporting " & lngCount & " contacts to Excel"
strTitle = "Exporting"
MsgBox strPrompt, vbInformation + vbOKOnly, strTitle
End If
'Go to first data cell
Set wks = wkb.Sheets(1)
wks.Activate
Set rngStart = wks.Range("A4")
rngStart.Activate
Thank you,
CujoFreak
I am trying to create a VB code that will help automate sales Orders, however I am receiving Error #91 when I am trying to compile the code. I was wondering if someone could provide me with assistance. Here is the portion of the code that is erroring out at the line 'Set rngStart = wks.Range("A4")':
Set appExcel = GetObject(, "Excel.Application")
'Set reference to worksheet and activate it
Set bks = appExcel.Workbooks
'Create and open new, blank workbook
bks.Add
'Make the worksheet visible
appExcel.Application.Visible = True
'Set reference to query
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("qryOrders", dbOpenDynaset)
rst.MoveLast
rst.MoveFirst
lngCount = rst.RecordCount
If lngCount = 0 Then
MsgBox "No contacts to export"
GoTo ErrorHandlerExit
Else
strPrompt = "Exporting " & lngCount & " contacts to Excel"
strTitle = "Exporting"
MsgBox strPrompt, vbInformation + vbOKOnly, strTitle
End If
'Go to first data cell
Set wks = wkb.Sheets(1)
wks.Activate
Set rngStart = wks.Range("A4")
rngStart.Activate
Thank you,
CujoFreak