Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Recover VBA code from corrupted .xls file?

Excel 2002: Several days' work is tied up in an .xls file that
mysteriously got corrupted and now I can't open it without Microsoft
"repairing" it by stripping out all the VBA code and the embedded
controls.

I have medium-level macro security control turned on, and I disable
macros when opening the file, but it still comes up with "Microsoft
Excel has encountered a problem and needs to close". Then if I take
the option to "recover and restart", all the VBA code is stripped out.

Is there any way to bypass opening the file with Excel and extract the
VBA modules?

Thanks,
Ken Dahlberg
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 96
Default Recover VBA code from corrupted .xls file?

Here are two links that deal with corrupted workbooks.

http://groups.google.com/groups?hl=e...NGP09&rn um=3
http://groups.google.com/groups?as_u...07@cppssbbsa03

----------------------------------------------------------------------------------------------------

The following is from a posting April 30, 1999 by Rob Bruce. Run this
macro from Word VBA to recover modules from corrupt Excel files.

'\for this macro to run you need to establish a reference to the
'\Microsoft Excel 8.0 Object Library
'\also, if you get a File Open error message, hit Debug, then Continue

Sub Recover_Excel_VBA_modules()

Dim XL As Excel.Application
Dim XLVBE As Object
Dim i As Integer, j As Integer

Set XL = New Excel.Application

XL.Workbooks.Open FileName:="h:\CR - Portfolio Template.xls"

Set XLVBE = XL.VBE

j = XLVBE.VBProjects(1).VBComponents.Count

For i = 1 To j
Debug.Print XLVBE.VBProjects(1).VBComponents(i).Name
XLVBE.VBProjects(1).VBComponents(i).Export
FileName:="C:\temp\vbe_"
& (100 + i) & ".txt"
Next

XL.Quit
Set XL = Nothing

End Sub

-----------------------------------------------------------------------------------------------------------------

Watch for line wrap. Once you've figured out how to recover your code,
use the following subroutine to back up your code. This subroutine
will collect all your hard work in appropriate folders for that time
when Excel junks another file. I backup each time I make changes to my
code.

You need to set a reference to "Microsoft Visual Basic for
Applications Extensibility" library.

Sub ExportAllVBA(Optional varName As Variant)
'' Exports all Modules, etc. to folder named the same as the Workbook.

Dim VBComp As VBIDE.VBComponent
Dim PartPath As String
Dim NextPartPath As String
Dim TotalPath As String
Dim Sfx As String
Dim d As Integer

If IsMissing(varName) Then varName = ActiveWorkbook.Name Else
varName = CStr(varName)

PartPath = "C:\Money Files\Computer Helpers\Modules\"
NextPartPath = Left$(ActiveWorkbook.Name, Len(ActiveWorkbook.Name)
- 4)

On Error Resume Next
TotalPath = PartPath & NextPartPath
ChDir TotalPath
If Err.Number = 76 Then MkDir TotalPath
On Error GoTo ErrExport

For Each VBComp In ActiveWorkbook.VBProject.VBComponents
Select Case VBComp.Type
Case vbext_ct_ClassModule, vbext_ct_Document
Sfx = ".cls"
Case vbext_ct_MSForm
Sfx = ".frm"
Case vbext_ct_StdModule
Sfx = ".bas"
Case Else
Sfx = ""
End Select
If Sfx < "" Then
VBComp.Export _
Filename:=PartPath & NextPartPath & "\" & VBComp.Name &
Sfx
End If
Next VBComp

Exit Sub

ErrExport:

MsgBox "The reason for this message:" & vbCrLf & "The Error Number
is: " & Err.Number _
& vbCrLf & "The Error Description is: " & Err.Description

End Sub

-------------------------------------------------------------------------------------------------------------
HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------
Excel 2002: Several days' work is tied up in an .xls file that
mysteriously got corrupted and now I can't open it without Microsoft
"repairing" it by stripping out all the VBA code and the embedded
controls.

I have medium-level macro security control turned on, and I disable
macros when opening the file, but it still comes up with "Microsoft
Excel has encountered a problem and needs to close". Then if I take
the option to "recover and restart", all the VBA code is stripped out.

Is there any way to bypass opening the file with Excel and extract the
VBA modules?

Thanks,
Ken Dahlberg


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Recover VBA code from corrupted .xls file?

Paul,
Thank you! This is going to be very helpful.
Ken
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help me recover my corrupted ms excel file! [email protected] Excel Discussion (Misc queries) 5 September 24th 15 10:26 AM
.xls .doc files have become corrupted after BSOD!!! how recover? jonty Excel Discussion (Misc queries) 6 April 7th 10 03:20 AM
recover corrupted excel 2007 file Loz New Users to Excel 3 October 30th 08 03:02 PM
How to recover Excel file from corrupted C: drive recycle bin? Ruel Excel Discussion (Misc queries) 0 March 26th 06 11:54 PM
Corrupted Code? Otto Moehrbach[_5_] Excel Programming 1 September 18th 03 11:18 PM


All times are GMT +1. The time now is 05:20 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"