Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Getting source code from Normal.dot

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rhino - 02 Feb 2006 21:02 GMT
I've spent the last few days working on a series of interrelated macros;
basically, there is a main macro and it farms out lots of its work to lesser
procedures. All of this code is working well and is stored in Normal.dot.

Is there any way that I can get the source code from Normal.dot and write it
to a text file invisibly? I realize that I could do this job manually by:
- opening the Visual Basic Editor from my document
- clicking Edit/Select All
- clicking Copy
- opening a text file outside of Word
- pasting the clipboard into the text file
- saving the text file

But I will probably make several more minor changes to the macros before
they're absolutely finished so I'd like to find a way to get the source code
of the macros "automagically", ideally with a VBScript that invokes a macro
that writes all of the macros in Normal.dot to a specified text file.

Can anyone tell me what to do?

I can write the VBScript that will drive all of this but I'm really not sure
how to capture the contents of Normal.dot so that I can write it to a file.
Even if I just record a macro that does the manual steps that I've listed
above, I don't have any idea how to open a text file, paste the clipboard
and save the text file programmatically.

I just tried recording a macro that did all that but the only line in the
macro is 'ShowVisualBasicEditor = True' so that's obviously not going to do
the job.

I'm using Word 2002.

--
Rhino
Jezebel - 02 Feb 2006 21:50 GMT
Use the Export function --

application.VBE.ActiveVBProject.VBComponents(2).Export "C:\MyModuule.txt"

> I've spent the last few days working on a series of interrelated macros;
> basically, there is a main macro and it farms out lots of its work to
[quoted text clipped - 33 lines]
> --
> Rhino
Rhino - 03 Feb 2006 15:43 GMT
Wow, that was a lot easier than I expected!

FYI, I had to go to Tools/Macro/Security and check the "Trust access to
Visual Basic Project" box on the Trusted Sources page before the Export
would work. Luckily, I'd seen Jay's reply as well as yours before trying
either solution :-)

I'm just mentioning this in case anyone else sees this thread and finds that
the Export command doesn't work for them; they may not have had that box
checked either :-)

Rhino

> Use the Export function --
>
[quoted text clipped - 37 lines]
>> --
>> Rhino
Jay Freedman - 02 Feb 2006 22:37 GMT
> I've spent the last few days working on a series of interrelated
> macros; basically, there is a main macro and it farms out lots of its
[quoted text clipped - 31 lines]
>
> I'm using Word 2002.

First, you need to go to Tools > Macro > Security, on the Trusted Sources
tab, and check the box for "Trust access to Visual Basic Project". Otherwise
your code will be denied access to the VBA projects.

Then, in the editor, go to Tools > References and check "Microsoft Visual
Basic for Applications Extensibility 5.3".

Finally, run this code (alter the dumpPath string as needed first):

Sub DumpNormalMacros()
  Dim comp As VBComponent
  Dim fn As String
  Const dumpPath = "C:\temp\vba\"

  For Each comp In VBE.VBProjects("Normal").VBComponents
     With comp
        Select Case comp.Type
        Case vbext_ct_ClassModule, vbext_ct_Document
           fn = dumpPath & comp.Name & ".cls"
        Case vbext_ct_StdModule
           fn = dumpPath & comp.Name & ".bas"
        Case vbext_ct_MSForm
           fn = dumpPath & comp.Name & ".frm"
        End Select

        .Export fn

     End With
  Next
End Sub

This automates what you can do manually: In the Project pane, right-click
each module and select Export File, and supply a name.

You can read these files into  any template project by right-clicking a
module and selecting Import File.

The .cls, .bas, and .frm files are plain text that you can read with
Notepad. The .frm file is accompanied by a .frx file that contains the
binary data for the form.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Rhino - 03 Feb 2006 15:59 GMT
>> I've spent the last few days working on a series of interrelated
>> macros; basically, there is a main macro and it farms out lots of its
[quoted text clipped - 73 lines]
> Notepad. The .frm file is accompanied by a .frx file that contains the
> binary data for the form.

Thanks, Jay! Your solution works as well as Jezebel's with the bonus of also
getting the .cls and .frm files. I don't actually have any forms at this
point so I'm not getting any .frm file and I'm not sure what to do with the
.cls file that I am getting but your solution is more complete and will be
very handy when and if I start using forms.

By the way, what was the point of adding that VBA manual to my
Tools/References?

--
Rhino
Jean-Guy Marcil - 03 Feb 2006 16:20 GMT
Rhino was telling us:
Rhino nous racontait que :

> By the way, what was the point of adding that VBA manual to my
> Tools/References?

The "VBComponent" type is not part of the Word VBA Object library.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Rhino - 03 Feb 2006 18:30 GMT
> Rhino was telling us:
> Rhino nous racontait que :
[quoted text clipped - 3 lines]
>
> The "VBComponent" type is not part of the Word VBA Object library.

Ahh, so installing the reference manual also installs code into VB? That's
unexpected!

Thanks for explaining that.

--
Rhino
Jean-Guy Marcil - 03 Feb 2006 19:31 GMT
Rhino was telling us:
Rhino nous racontait que :

>> Rhino was telling us:
>> Rhino nous racontait que :
[quoted text clipped - 6 lines]
> Ahh, so installing the reference manual also installs code into VB?
> That's unexpected!

Well, actually, you are not installing a manual.
You are telling the Word VBA compiler that you are going to use some objects
from a library that is not loaded by default, so you loaded it yourself.

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Jay Freedman - 03 Feb 2006 19:53 GMT
> Rhino was telling us:
> Rhino nous racontait que :
[quoted text clipped - 14 lines]
> objects from a library that is not loaded by default, so you loaded
> it yourself.

Hi Rhino,

In case you aren't familiar with the term, "library" as Jean-Guy used it
means a file of compiled code, usually in a "dynamic link library" or DLL.
In the References dialog, when you select the item "Microsoft Visual Basic
for Applications Extensibility", the bottom of the dialog shows you which
DLL it's pointing to (or at least it would, if somebody at MS had the
foresight to make the label area larger so the path wasn't truncated):

C:\Program Files\Common Files\Microsoft Shared\VBA\VBA6\VBE6.DLL

This does have the side effect of enabling the Help topics for the objects
that live in the DLL. On a computer that uses the English version of
Windows, those topics are in the file ...\VBA6\1033\VBOB6.CHM. To get to
them easily in the editor, put the cursor on the name of any object, method,
or property that belongs to the VBE stuff and press F1.

Signature

Regards,
Jay Freedman
Microsoft Word MVP          FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Jean-Guy Marcil - 03 Feb 2006 20:25 GMT
Jay Freedman was telling us:
Jay Freedman nous racontait que :

>> Rhino was telling us:
>> Rhino nous racontait que :
[quoted text clipped - 29 lines]
> This does have the side effect of enabling the Help topics for the
> objects that live in the DLL. On a computer that uses the English

If there is a help file...

> version of Windows, those topics are in the file
> ...\VBA6\1033\VBOB6.CHM. To get to them easily in the editor, put the
> cursor on the name of any object, method, or property that belongs to
> the VBE stuff and press F1.

Thanks Jay...

One day.. I'll be as thorough as you are!

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.