|
-
Apr 15th, 2009, 04:32 PM
#1
Thread Starter
Hyperactive Member
Object invoke error ... sometimes
Hello all,
I'm experiencing a rather frustrating error in both Excel VBA 2003/2007. It only happens sometimes (somewhat rarely), during the below code. I have 5 necessary references, which I can list if need be. Having read the MS help ( http://support.microsoft.com/default...;en-us;Q319832 ) on this topic I feel I may need to "fully qualify" my object references in the below code, but don't really know how to go about doing that...
Here's the code w/ the problem. The below code essentially opens and copies a worksheet from a workbook into the active workbook, then closes the workbook.
vb Code:
Application.DisplayAlerts = False
Dim sfilename As String
sfilename = Application.GetOpenFilename(filefilter:="Excel Files (*.xls), *.xls", Title:="N-INDEX")
If sfilename = "False" Then Exit Sub
Dim temp As String
temp = spliceFileNameEnd2(sfilename)
Dim shtnext As Variant
For Each shtnext In Sheets
If shtnext.name = "pindexCA" Then 'Search/Delete charts w/ same name
Sheets("pindexCA").Visible = True
Application.DisplayAlerts = False 'No delete prompt
Sheets("pindexCA").Delete
End If
Next shtnext
Workbooks.Open FileName:=sfilename
Dim found As Boolean
found = False
For Each shtnext In Sheets
If shtnext.name = "pindexCA" Then
found = True
Exit For
End If
Next shtnext
If found = False Then
Workbooks(temp).Close SaveChanges:=False
MsgBox ("No P-Index File was found in that file.")
Sheets.Add
ActiveSheet.name = "pindexCA"
Sheets("pindexCA").Visible = xlVeryHidden
Exit Sub
End If
Sheets("pindexCA").Copy After:=Workbooks(ThisWorkbook.name).Sheets(ThisWorkbook.Sheets.count)
Workbooks(temp).Close SaveChanges:=False
Sheets("pindexCA").Visible = xlVeryHidden
Sheets("Driver").Activate
Application.DisplayAlerts = True
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|