I have an app which validates and imports excel files into Access with a module that checks the Tab names then sets certain columns to "General" format.
The first file works ok then the second call of the module gives Run-time error 91 - "Object variable or With block variable not set"
Module:
------------------
Option Compare Database
Option Explicit
Function fncXLTabCheck1(frmM As Form, strPath As String, strImpFile As String, strType As String)
Dim appExcel As Object
Dim Wks As Worksheet
Set appExcel = CreateObject("Excel.Application")
appExcel.Workbooks.Open strPath & strImpFile, UpdateLinks:=0
For Each Wks In appExcel.Worksheets
If Trim(UCase(Wks.Name)) = "MONTH" Then
Wks.Name = "xxMonth-" & Format(Now(), "yyyymmddhhnn")
End If
Next
For Each Wks In appExcel.Worksheets
If Trim(UCase(Wks.CodeName)) = "MONTH" Then
Wks.Name = "Month"
frmM!intSheet = frmM!intSheet + 1
If strType = "OCEAN" Then
Wks.Columns("M:N").Select
Selection.NumberFormat = "General"
ElseIf strType = "AIR" Then
Wks.Columns("L").Select
Selection.NumberFormat = "General"
Wks.Columns("N").Select
Selection.NumberFormat = "General"
End If
End If
Next
appExcel.ActiveWorkbook.Close SaveChanges:=True
' set appExcel = nothing 'makes no difference
End Function
------------------
Setting appExcel = nothing makes no difference to the problem
Possible problem is brainfade, but I would appreciate any help!
Thanks
The first file works ok then the second call of the module gives Run-time error 91 - "Object variable or With block variable not set"
Module:
------------------
Option Compare Database
Option Explicit
Function fncXLTabCheck1(frmM As Form, strPath As String, strImpFile As String, strType As String)
Dim appExcel As Object
Dim Wks As Worksheet
Set appExcel = CreateObject("Excel.Application")
appExcel.Workbooks.Open strPath & strImpFile, UpdateLinks:=0
For Each Wks In appExcel.Worksheets
If Trim(UCase(Wks.Name)) = "MONTH" Then
Wks.Name = "xxMonth-" & Format(Now(), "yyyymmddhhnn")
End If
Next
For Each Wks In appExcel.Worksheets
If Trim(UCase(Wks.CodeName)) = "MONTH" Then
Wks.Name = "Month"
frmM!intSheet = frmM!intSheet + 1
If strType = "OCEAN" Then
Wks.Columns("M:N").Select
Selection.NumberFormat = "General"
ElseIf strType = "AIR" Then
Wks.Columns("L").Select
Selection.NumberFormat = "General"
Wks.Columns("N").Select
Selection.NumberFormat = "General"
End If
End If
Next
appExcel.ActiveWorkbook.Close SaveChanges:=True
' set appExcel = nothing 'makes no difference
End Function
------------------
Setting appExcel = nothing makes no difference to the problem
Possible problem is brainfade, but I would appreciate any help!
Thanks