Unexpected Error 91 message

S

scruffy

I am about to pull my hair out because I feel like I have missed something
but I can't figure out what it is.

I created a user form in Word 2000 that opens templates in both Word 2000
and Excel 2000 and saves the .doc or .xls upon creation to the appropriate
folder for field personnel. (i.e. Travel, Work Records, etc.)
The form contains a check box to open an existing document that the field
personnel select from a list in an explorer window (DialogOpen).
We have Office 2003 installed on our test laptop on which the form functions
perfectly.
We have Office 2003 and Office 2007 installed on a new test laptop on which
all folders with Word documents will show but none of the Excel files will
show after they are created (they can be seen by using the My Computer method
to see the files).
We did not change the code and I have gone over the code line by line but
cannot see anything wrong with it yet the folders with the existing Excel.xls
files all produce the error message: Error 91- Object variable or with block
variable not set.
I know where the code is producing the error but cannot figure out why it
works on one laptop with Office 2003 and not the other. Both laptops are
running Windows XP. Could having Office 2007 installed as well as Office 2003
but 2003 being set as the default be the culprit?

I have included some code and think the "Case Is = vbNo" portion is what is
producing the error.

Case Is = "exl"
If CheckBox1 = False Then
mFile = fPath & mFolder & "\" & mDealer.Value & mLocation.Value & mForm
& "-" & Year(mDate.Value) & "." & Month(mDate.Value) & "." & Day(mDate.Value)
& ".xls"
mResponse = MsgBox("You have entered file " & mFile & vbCrLf & "Click
'OK' to create this file." & vbCrLf & "Click 'Cancel' to select another file
type.", vbOKCancel, "Click to continue?")
Else
mResponse = vbNo
End If
Select Case mResponse
Case Is = vbOK
Set mApp = CreateObject("Excel.Application")
mApp.Workbooks.Open FileName:=mFile
If Err.Number <> 0 Then
XLWBNotExist = True
Err.Clear
End If
If XLWBNotExist = True Then
mApp.Workbooks.Add Template:=wkgPath & mTemplate
mApp.ActiveWorkbook.SaveAs FileName:=mFile
' mApp.ActiveWorkbook.SaveAs FileName:=mFile,
FileFormat:=xlExcel9795
End If
mApp.Visible = True
Case Is = vbNo
mFile = ""
Set xlApp = CreateObject("Excel.Application")
xlApp.DefaultFilePath = fPath & mFolder
Set xlApp = Nothing
Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlDlg = xlApp.Dialogs(xlDialogOpen)
xlDlg.Show
Set xlApp = Nothing
Set xlDlg = Nothing
Case Is = vbCancel
Exit Function
End Select
End Select
mFolderPass = mFolder
ExitHere:
Exit Function

Any help would be greatly appreciated.
 
S

scruffy

After researching the situation it was determined that the reference for 2003
was removed when the templates were opened up in 2007 compatibility mode.
After resetting the references and recompiling the main form everything
worked fine.

Hope this helps others in the future with a similar situation.

Scruffy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top