ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Extracting (copying) modules from one workbook to another. (https://www.excelbanter.com/excel-programming/333767-extracting-copying-modules-one-workbook-another.html)

Devin Linnington

Extracting (copying) modules from one workbook to another.
 
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.




William Benson[_2_]

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.







All times are GMT +1. The time now is 11:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com