New document from existing - "lost macros"?

Y

yzi

Hello,

I have empty document with one module and this sub:

Public Sub TestMessage()
MsgBox ("Test")
End Sub

This document is saved as doc1.doc (Word document - not template).
Now I choose File - New from existing and select doc1.doc so new document is
created.
The problem is that I cannot see macro TestMessage in list of macros for run
(Alt+F8). If I open editor and i.e. change name of module or recompile
project - I can see that macro.
Where is the problem? I have to see it when new document is opened. I can
change the name of module (it probably invoke recompile) programmatically but
Truth access VBA project must be checked :-(
Thanx.
PS: I cannot use template (.dot)
 
D

Doug Robbins - Word MVP on news.microsoft.com

Why can't you use a template?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
Y

yzi via OfficeKB.com

This is simple example. In real "doc1.doc" has attached template (with
digital signature) which I cannot modify.
 
Y

yzi via OfficeKB.com

This is simple example. In real "doc1.doc" has attached template (with
digital signature) which I cannot modify.
 
T

Tony Jollans

I see what you say, and I have occasionally seen similar problems. I don't
think there is much you can do except acknowledge the issue and work round
it.

Your post is confusing, though. Are you wanting to access the code from the
UI (Alt+F8), which may be a problem, or from VBA (Trust programmatic access
needed), which should be OK?
 
Y

yzi via OfficeKB.com

I want the macro be called in checkbox events (OnEnter, OnExit). But if you
look at checkbox properties, dropdown for selecting macros for this event are
empty (same as in UI Alt+F8). If you do compile project, assigned macros for
this events is OK and you can see them in dropdowns.
 
Y

yzi via OfficeKB.com

I want the macro be called in checkbox events (OnEnter, OnExit). But if you
look at checkbox properties, dropdown for selecting macros for this event are
empty (same as in UI Alt+F8). If you do compile project, assigned macros for
this events is OK and you can see them in dropdowns.
 
T

Tony Jollans

I tried several things and this was all I could manage to get to work. It's
a bit heavy handed but it's worth a try, and it doesn't seem to need "trust
access" set. Put this in the "ThisDocument" module of your base document,
and change the constant to the name of your module.

Private Sub Document_New()

Const ModuleName As String = "Albert"
Dim Doc1 As Document, Doc2 As Document
Set Doc1 = ActiveDocument
Set Doc2 = Documents.Add(Visible:=False)

Application.OrganizerCopy Source:=Doc1.Name, _
Destination:=Doc2.Name, _
Name:=ModuleName, _
Object:=wdOrganizerObjectProjectItems
Application.OrganizerDelete Source:=Doc1.Name, _
Name:=ModuleName, _
Object:=wdOrganizerObjectProjectItems
Application.OrganizerCopy Source:=Doc2.Name, _
Destination:=Doc1.Name, _
Name:=ModuleName, _
Object:=wdOrganizerObjectProjectItems

Doc2.Close wdDoNotSaveChanges

End Sub
 

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