Run-time error 9

  • Thread starter Thread starter L Guest
  • Start date Start date
L

L Guest

I am getting a run-time error 9 when I am trying to
activate a workbook that is not open from inside another
workbook. I saw in the knowledge base that this is a
known issue in Excel 2000 as issue #271595. They suggest
inserting a module with the following code to fix. Has
anyone been able to make this work?

Sub ActivateSheet()
On Error Resume Next
Workbooks("Workbook2").Activate
Workbooks("Workbook2.xls").Activate
On Error GoTo 0
If Not ActiveWorkbook.Name = "Workbook2.xls" And
Not _
ActiveWorkbook.Name = "Workbook2" Then
Workbooks.Open Filename:="Workbook2.xls"
End If
End Sub
 
Try this example that trap the error

Sub test()
Dim Wb As Workbook
On Error Resume Next
Set Wb = Workbooks("Workbook2.xls")
On Error GoTo 0
If Wb Is Nothing Then
Set Wb = Workbooks.Open("C:\Workbook2.xls")
Else
'do nothing
End If
Wb.Activate
End Sub
 

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

Back
Top