ChrisOswald
Active Member
- Joined
- Jan 19, 2010
- Messages
- 454
This is a pretty general question: the code below actually resides in an Access 2003 db. (in case you're wondering why I'm passing a worksheet as an Excel.worksheet)
On only one persons computer, the code is breaking on the Set cloc = ws.cells.find ... line with an error 13 'Type Mismatch'. Everyone else using this (or similar routines) isn't having a problem.
Some background: A while back (a few weeks ago), the person had some problems with their email. The IT help desk decided the "fix" was to upgrade their Outlook to 2007 (leaving MS office 2003 for the rest of the office suite), found out it didn't work, and then reinstalled Outlook 2003.
Playing around in the immediate window in debug mode, ?ws.name returns correctly, ?ws.cells(2,2) returns the value in cell B2, etc, but ?ws.usedrange.rows.count (for example) gives another error 13.
So, do you think that it's worth getting IT to do a full reinstall, or is it something silly on my part?
(BTW, the C:\Temp.xls file does exist)
Code:
Sub TestIt()
Dim wb As Excel.Workbook
Dim WS As Excel.Worksheet
Dim appXL As Excel.Application
Dim LR As Long
Set appXL = New Excel.Application
Set wb = appXL.Workbooks.Open("C:\Temp.xls")
Set WS = wb.Worksheets("Corporate_Request_tbl")
LR = GetLastRow(WS)
MsgBox (LR)
wb.Close
Set WS = Nothing
Set wb = Nothing
appXL.Quit
Set appXL = Nothing
End Sub
Function GetLastRow(WS As Excel.Worksheet) As Long
Dim cloc As Excel.Range
Dim LastRow As Long
Set cloc = WS.Cells.Find(what:="*", After:=WS.Cells(1, 1), searchorder:=xlByRows, SearchDirection:=xlPrevious)
If cloc Is Nothing Then
LastRow = 0
Else
LastRow = cloc.Row
End If
Set cloc = Nothing
GetLastRow = LastRow
End Function
On only one persons computer, the code is breaking on the Set cloc = ws.cells.find ... line with an error 13 'Type Mismatch'. Everyone else using this (or similar routines) isn't having a problem.
Some background: A while back (a few weeks ago), the person had some problems with their email. The IT help desk decided the "fix" was to upgrade their Outlook to 2007 (leaving MS office 2003 for the rest of the office suite), found out it didn't work, and then reinstalled Outlook 2003.
Playing around in the immediate window in debug mode, ?ws.name returns correctly, ?ws.cells(2,2) returns the value in cell B2, etc, but ?ws.usedrange.rows.count (for example) gives another error 13.
So, do you think that it's worth getting IT to do a full reinstall, or is it something silly on my part?
(BTW, the C:\Temp.xls file does exist)