Link to home
Start Free TrialLog in
Avatar of Delboy
DelboyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Corrupt Excel Workbook

I have a workbook containing 2 userforms and 2 modules of VBA code (Excel97).  It now crashes Excel when I go into the Visual Basic Editor and I can't get to my code..  but it does run the forms and the code via an AutoOpen macro..  I have tried Excel Recovery version 1 but it only recovers the AutoOpen macro....  

Help...  Delboy
Avatar of awd
awd

Try holding down the shift key when you open the workbook.  This should prevent the macro from running.  That way you ahould be able to get into the workbook and fix the problem.
Avatar of Delboy

ASKER

This only stops the AutoOpen macro, but still cannot get into the visual basic editor without crashing once in the workbook...
I see. I misunderstood your problem. I will give it some more thought.
Avatar of Delboy

ASKER

I look forward to it..  D.
Delboy,

If you will send the file to me, I'll take a look at it and see if I can get to your code. You can send the file to shalbe@san.rr.com

Steve
Delboy,

What happens when it crashes?
Avatar of Delboy

ASKER

It crashes Excel altogether...
Hi,

Could you send the file to me as well please.  I think I can get at the code only using a handle.

frazer@flying-worm.demon.co.uk

regards

Frazer
Have you tried copying the workbook to a new file to see if the problem persists?  What if you try getting at the code through the Tools-Macro-Macros menu option?  Do you get the same behavior?  Can you delete macros from this spot?  Can you access the code editor in other workbooks?
Avatar of Delboy

ASKER

Everything you have just said, I have done to no avail...nice try though awd...  copying to a new workbook brings the problem with it, going through the Tools etc option has the same results, cannot delete macros .. and can go into the editor in other workbooks..  

D
ASKER CERTIFIED SOLUTION
Avatar of shalbe
shalbe

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,

alternativly,

here is your code....


'Module1


Sub Auto_Open()
    ScreenUpdating = False
    UserForm2.Show
End Sub



'UserForm1


Private Sub CommandButton1_Click()
    If UserForm1.TextBox2.Value = """" Then
    MsgBox ""Please Fill In The Name Field"", vbExclamation, ""Name""
        UserForm1.TextBox2.SetFocus
        Exit Sub
    End If
    If UserForm1.TextBox4.Value = """" Then
    MsgBox ""Please Fill In The Project Field"", vbExclamation, ""Project""
        UserForm1.TextBox4.SetFocus
        Exit Sub
    End If
    If UserForm1.TextBox1.Value = """" Then
    MsgBox ""Please Fill In The Date Field"", vbExclamation, ""Date""
        UserForm1.TextBox1.SetFocus
        Exit Sub
    End If
    If UserForm1.TextBox8.Value = """" Then
    MsgBox ""Please Fill In The Start Date Field"", vbExclamation, ""Start Date""
        UserForm1.TextBox8.SetFocus
        Exit Sub
    End If
    If Label25.Visible = True Then
        MsgBox ""Please Enter A Valid Start Date In The Start Date Field"", vbExclamation, ""Start Date""
        UserForm1.TextBox8.SetFocus
        Exit Sub
    End If
    If UserForm1.TextBox5.Value = """" Then
    MsgBox ""Please Fill In The Team Leader Field"", vbExclamation, ""Team Leader""
        UserForm1.TextBox5.SetFocus
        Exit Sub
    End If
    If UserForm1.TextBox6.Value = """" Then
    MsgBox ""Please Fill In The Supervisor Field"", vbExclamation, ""Supervisor""
        UserForm1.TextBox6.SetFocus
        Exit Sub
    End If
    If UserForm1.TextBox7.Value = """" Then
    MsgBox ""Please Fill In The Manager Field"", vbExclamation, ""Manager""
        UserForm1.TextBox7.SetFocus
        Exit Sub
    End If
   
   
    Dim Y As Integer
    Sheets(""Datasheet"").Range(""A2"").Value = UserForm1.TextBox2.Text
    Sheets(""Datasheet"").Range(""B2"").Value = UserForm1.TextBox4.Text
    Sheets(""Datasheet"").Range(""C2"").Value = UserForm1.TextBox1.Text
    Sheets(""Datasheet"").Range(""D2"").Value = CDate(UserForm1.TextBox8.Text)
   
    If UserForm1.OptionButton1.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""E2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton2.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""E2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton3.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""E2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton4.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""E2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton5.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""F2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton6.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""F2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton7.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""F2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton8.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""F2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton9.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""G2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton10.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""G2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton11.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""G2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton12.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""G2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton13.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""H2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton14.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""H2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton15.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""H2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton16.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""H2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton17.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""I2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton18.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""I2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton19.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""I2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton20.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""I2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton21.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""J2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton22.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""J2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton23.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""J2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton24.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""J2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton25.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""K2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton26.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""K2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton27.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""K2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton28.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""K2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton29.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""L2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton30.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""L2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton31.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""L2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton32.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""L2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton33.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""M2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton34.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""M2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton35.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""M2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton36.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""M2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton37.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""N2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton38.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""N2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton39.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""N2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton40.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""N2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton41.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""O2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton42.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""O2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton43.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""O2"").Value = UserForm1.OptionButton1.Caption
    End If
    If UserForm1.OptionButton44.Value = True Then
        Y = Y + 1
        Sheets(""Datasheet"").Range(""O2"").Value = UserForm1.OptionButton1.Caption
    End If
    If Y <> 11 Then
        MsgBox ""You haven't answered all questions, please try again"", vbExclamation, ""Answer All Questions""
    End If
    Sheets(""Datasheet"").Range(""P2"").Value = UserForm1.TextBox5.Text
    Sheets(""Datasheet"").Range(""Q2"").Value = UserForm1.TextBox6.Text
    Sheets(""Datasheet"").Range(""R2"").Value = UserForm1.TextBox7.Text
    OpenFeedData
    Workbooks(""feed.xls"").Activate
    Rows(""2:2"").Select
    Selection.Copy
    Windows(""FEEDDATA.XLS"").Activate
    Range(""A1"").Select
    If IsEmpty(Range(""A2"")) Then
        Selection.Offset(1, 0).Select
    Else
        Selection.End(xlDown).Select
        Selection.Offset(1, 0).Select
    End If
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=False
    Range(""A1"").Select
    Workbooks(""Feeddata.xls"").Close savechanges = True
End Sub

Private Sub CommandButton2_Click()
    Workbooks(""Feed.xls"").Close savechanges = False
End Sub

Private Sub TextBox1_Change()

End Sub

Private Sub TextBox8_Change()
    If IsDate(TextBox8.Value) Then
    Label25.Visible = False
    Else
        Label25.Visible = True
        TextBox8.SetFocus
    End If
End Sub

Private Sub UserForm_Activate()
    TextBox1.Value = Format(Date, ""short date"")
    TextBox8.Value = Format(Date + 14, ""short date"")
End Sub
Function OpenFeedData()
    On Error GoTo ErrorHandler
    For X = 1 To 10000
        Workbooks.Open (""i:\users\jeed\data\xls\FeedData.xls"")
        X = 10000
    Next
Exit Function
ErrorHandler:
    Select Case Err.Number
        Case 55
            Resume
        Case Else
            Debug.Print Error(ErrorNumber)
    End Select
End Function




'UserForm2

Private Sub CommandButton1_Click()
UserForm1.Show

End Sub


Hope this helps

Frazer
Avatar of Delboy

ASKER

Thanks Steve, it works fine now..  I see the error of my ways..

Derek.