Extracting (copying) modules from one workbook to another.

  • Thread starter Devin Linnington
  • Start date
D

Devin Linnington

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.
 
W

William Benson

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.
 

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

Top