Insert Macro from Access into normal.dot (Word 2000)

H

Henrootje

My users instist on using the standard export function of Access to
export reports from Access to Word, even though they loose the
formatting. Then a macro should repair the formatting as far as
possible).

I made that macro but it needs to be in the normal.dot to be accessible
form the *.rtf that Access makes. In our company the normal.dot is
replaced every night with a blank one. Is there a way to insert the VB
of the macro into the normal.dot upon starting the DB?

ie: I am thinking of code that will export the text of the macro to the
normal.dot so that when the user starts his/hers Word the macro is
available????


TIA Henro
 
D

David Lloyd

Henro:

The following sample shows one method for accomplishing this. Needless to
say this type of operation is fraught with security issues. In order for
this code to work correctly you will need to change a security setting.
Select Tools, Macros, Security and under the Trusted Publishers tab, select
Trust Access to Visual Basic Project. This code first checks to see if the
module exists, and if not, imports a code file into the Normal template.

Function AddWordMacro()
Dim wd As New Word.Application
Dim doc As Word.Document
Dim vbc As VBComponent
Dim bExists As Boolean

On Error GoTo Errorhandler

Set doc = wd.NormalTemplate.OpenAsDocument

For Each vbc In doc.Application.NormalTemplate.VBProject.VBComponents
If vbc.Name = "MyModuleName" Then bExists = True
Next vbc

If Not bExists Then
doc.Application.NormalTemplate.VBProject.VBComponents.Import
("C:\WordModule.bas")
End If

doc.Close True

Function_Exit:

wd.Quit

Set doc = Nothing
Set vbc = Nothing
Set wd = Nothing

Exit Function

Errorhandler:

If Err.Number <> 0 Then
MsgBox "Error Number: " & Err.Number & vbCrLf & "Description: " &
Err.Description, vbOKOnly
Resume Function_Exit
End If
End Function

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


My users instist on using the standard export function of Access to
export reports from Access to Word, even though they loose the
formatting. Then a macro should repair the formatting as far as
possible).

I made that macro but it needs to be in the normal.dot to be accessible
form the *.rtf that Access makes. In our company the normal.dot is
replaced every night with a blank one. Is there a way to insert the VB
of the macro into the normal.dot upon starting the DB?

ie: I am thinking of code that will export the text of the macro to the
normal.dot so that when the user starts his/hers Word the macro is
available????


TIA Henro
 
D

Dave Emmert

In our offices, we use a seperate template (with buttons) located in the
Startup Folder for MS Word. That might be an easier way for you to go

Dave
 

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