View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
William Benson[_2_] William Benson[_2_] is offline
external usenet poster
 
Posts: 230
Default Extracting (copying) modules from one workbook to another.

If you cannot open the workbook manually, then a VBA macro like the below
can't work on it. The below is for copying code out of an open workbooks.
Sorry I cannot help you further.



"Devin Linnington" wrote in
message ...
Hi,
I screwed up, bigtime, and now I cannot open one of my workbooks. However,
I
really want to recover the project stored in it. All I need to do is
somehow
extract that data from the workbook without opening it. I have tried the
Office tool 'recover data' but when it repairs the file it deletes the
macros
(yes, they are that screwed up :P ). I found a website that offers a 'copy
all modules to another workbook' program for VBE, but trying it in the VBA
editor from excel doesn't work. If the program did work I think it would
solve my problem. Here is the code from that website:


Sub CopyAllModules()

Dim FName As String
Dim VBComp As VBIDE.VBComponent

With Workbooks("Book2")
FName = .Path & "\code.txt"
If Dir(FName) < "" Then
Kill FName
End If
For Each VBComp In .VBProject.VBComponents
If VBComp.Type < vbext_ct_Document Then
VBComp.Export FName
Workbooks("book1").VBProject.VBComponents.Import FName
Kill FName
End If
Next VBComp
End With
End Sub

It is the 'VBIDE.VBComponent' that doesn't work (not registered in VBA?)
and
I think that the 'VBComponents' doesn't work either. The website is
http://www.cpearson.com/excel/vbe.htm .
Can someone help me recover my project?
Thanks ahead of time for the help (once again)
Devin L.