Link to home
Create AccountLog in
Avatar of JohnRobinAllen
JohnRobinAllenFlag for Canada

asked on

Where does MS Word VBA Code?

Where does VBA store its code?

Can anyone tell me where to find several hundred lines of MS Word VBA code I wrote? Here is the genesis of that code. I have an Excel workbook with a database of a few thousand books that I want to contribute to some university library. 

I use Excel to hold the data, first because I’m fairly familiar with that program but do not know as well any equivalent database program such as Access. 

Second, I use Excel because it has more than enough power to manipulate the few thousand books now in my database. Unfortunately, Excel does not have the word processing power of Word, so I use that program for creating reports with the Excel data. 

The procedure is relatively simple:

  1. I manipulate the words in Excel to isolate a sorted subset of a few thousand books broken into seventeen fields. The fields control the sorting but, more importantly, control the formatting of individual entries that Word will generate. 
  2. I select the sorted Excel subset then copy it, switch to Word, and paste the selection as a Table in Word document.
  3. Here is where I have a problem. Normally in Word I open the VBA editor that contains around a thousand lines of code that I wrote and saved in previous sessions. The code is no longer there. 


Can anyone tell me where Word stores VBA code in this situation? I hope my work is not lost.

—John Robin Allen

Foothills (near Calgary), Alberta


Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Did you look in the VBA Editor?

On the Developer tab, click Visual Basic.

If you don’t see the Developer tab:

Click File > Options.

Click Customize Ribbon, and then, under Main Tabs, select the Developer check box.

Click OK.

In the Visual Basic Editor, on the Help menu, click Microsoft Visual Basic for Applications Help.

If you haven’t used Word VBA Help before, you will be asked to choose the browser in which you’d like help to be displayed.

In the browser, on the left pane, under Word, expand the Word VBA reference.

In the left pane, browse to find the concept, procedure, or object that you want help with, or type a query in the Search box at the top right corner of your screen.
Excel does not have the word processing power of Word
Maybe not, but if you can attach a small sample workbook showing worksheets with the report(s) you want I'm willing to try to write acceptable code to produce the report(s) in Excel.
click View > Macro > View Macros

Try: Alt-F11
Avatar of Eric Fletcher
Eric Fletcher
Flag of Canada image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of JohnRobinAllen


Slightwv’s comment suggested some places I should check for the missing code. I checked with no results. My major problem is that since I cannot find the missing code, I have nothing to search for. That is probably my fault.

Martin Liss’s offer is most welcome and may help me eventually to skip using Word as the last step in my system. After I finish this comment, I’m going to try to find a copy of my PDF code somewhere on my computer. I have made backup files on an almost daily basis, so there may be something hidden there.

Andrei Fomitchev’s suggestion to try F-11 only opened Word’s grammar checker, but his shortcut sequence (View, Macros, View Macros) displayed a list of all my macros. None of those suggested any part of my missing VBA code.

Eric Fletcher’s comment was by far the most useful. It showed me exactly where my code had been—probably only temporarily—stored and how it could possibly be retrieved.

I'll work a bit on those data and get back here with the results,
   —j.r. from Canada
Just an FYI, you left that last comment as a "Testimonial" instead of a "Comment".