Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Lost all my macros 2

Status
Not open for further replies.

dasmotiu

Programmer
Nov 30, 2010
8
0
0
US
I was just testing a new VBA macro in word, running it in the debugger step by step, and it reached an "insert hyperlink" statement which crashed word. After a while it seemed to recover, but the cursor was a long way away from where it had been, I needed to go to the end of the document which is where I was testing the macro. I pressed Ctrl-End and word instantly crashed again, and this time it did not recover. I reopened an unmodified version of the document, and found that ALL my VBA code has vanished. All of it, about 2000 lines of lines of code - weeks of work. Is there anywhere I can recover it from?
 
This sounds odd.

" I reopened an unmodified version of the document, and found that ALL my VBA code has vanished."

If it was unmodified, I have to assume that means unmodified with having your VBA code. This seems unlikely if you have been at it for weeks. Surely you must have saved the file during this time, and therefore it was modifed with the VBA code. Yes?

Are you saying unmodifed means it is a file from weeks ago, before you did any VBA?

If this is the case, then you are out of luck.

HOWEVER, if Word crashed, what happened when you started it up again? It did not offer you a recovery file?

You can possibly look for it in your recovery folder..maybe. But if you opened an unmodified file, you may be out of luck.

I am curious though as to what you may have been doing to have such a drastic effect. A Ctrl-End causing a crash seems VERY drastic, and unlikely...but - shrug - it IS Word. Why, specifically, was the cursor even moved at all?

So...what was your macro trying to do?

Like anything else, it is a good idea to save the file periodically. The save will save your VBA. If you are really cautious (and if you are writing massive amounts of code, although 2000 lines is a lot, it is not overly huge), it is also a good idea to export your code to .bas (and .frm) files - just in case. I do.

BTW: if you are doing a lot of code, with a lot of rewrites, it is also a good idea to export and import all your code, every once in a while. Word tends to bloat itself (surprise surprise). See VBA Code Cleaner. You can of course do your own export/import. Not only does this keep things cleaner, smaller, but it also acts as a backup for your code.

Good luck.

< 60 50 40 working days until retirement; with 87 accumulated sicks days. Know what? I am not feeling well.
 
Copy your code to NotePad as a text file, copy early and copy often.
 
If you are using Vista or W7 you may see 'Restore previous versions' as an option when you right click the file in Windows Explorer.
 



Copy your code to NotePad as a text file, copy early and copy often.
I EXPORT my code in the VBA Editor. Saves it as a *.bas

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Skip, I am ready to learn something new. Tell me what to do.

I found Export File. When I clicked on it, it took me to something called Office10.

So, where do I need to export the module to and how do I reopen it if I need the code. And, can I export to a USB (Flash) Drive.

Thanks.

WaterSrite
 

When I clicked on it, it took me to something called Office10
Navigate to wherever you care to keep your code modules.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
So, where do I need to export the module to and how do I reopen it if I need the code. And, can I export to a USB (Flash) Drive."

From the VBE, Export exports as either .bas (code modules), or .frm (userforms). They are simply text files really. The difference is that you can import them directly/programmatically into a VBA project.

They are just files, and the "where" you export them is wherever you want.

Exporting makes a copy. They originals are still in your project. You bring .bas files into a project by importing them.

The advantage of exporting is you can import them into another project programmatically.
Code:
ActiveDocument.VBProject.VBComponents.Import "c:\zzz\GerryTestImport.bas"
imports a code module GerryTestImport into the active document.

Can you write an export to a USB drive? Sure. However, generally speaking depending on flsh drives for anything is not such a great idea. I would export it to a hardrive folder, then copy it to your USB. They are small files.

< 60 50 40 working days until retirement; with 87 accumulated sicks days. Know what? I am not feeling well.
 
Fumei,

I understand your concern with use of Flash Drives for long term storage. But that is not what I am doing. We have no physical connection between the computers we use at work and the outside world. So, anything I figure out at home, help I get from here or from the internet, I have to copy it to a flash drive, take it to work, scan it on another computer for threats, then load it onto the computer where I write the code to control the spreadsheets we use. Usually I copy any and all code to NotePad, then copy notepad back to the Module or Macro where I want to use it.
 
No, the previous version of the document was from about an hour before.

I know where the code is located, (after all I had been stepping through the macro, as I said in my original post) and when I went back there, it was as if I had never recorded or written a single macro. Just to be sure, I recorded a one-line macro and sure enough, it was correctly recorded and editable and was the ONLY macro present. Everything just vanished without trace, and I now have to recreate them all... Yes, I know I should have a backup, by exporting, or even if I just cut-and-paste to a text file, but I have been using VBA since Word97 first came out, ie 13 years, and nothing like this has ever happened before.
 
WaterSprite: moving code as text in Notepad is quite acceptable, if it works for you. Not all that much difference. Instead of opening Notepad, copying the text, goin intot he VBE, opening a code mosule and pasting the text; you would use Import and point to the USB drive, and click OK.

dasmotiu: sorry but you are not be very clear. You did not respond to my question regarding "unmodified version of the document", nor to my question regarding what it was you were doing.

So are you saying:

1. recorded a one line macro
2. saved the file
3. closed the file
4. opened the file (the code is still there)
5. executed something and Word crashed
6. started up Word again, and opened the file
7. the code is NOT there.



< 60 50 40 working days until retirement; with 87 accumulated sicks days. Know what? I am not feeling well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top