Error trying to compile using VBA

A

Amir

Hi!



I'm trying to compile a normal.dot project using the following command:



application.VBE.VBProjects.Item("Normal").MakeCompiledFile



from the immediate window but I get the following error:



Run-time error '768'

Method or property is not valid in this type of project.





I don't know why is that. the Normal Project exists. If I type:

debug.print application.VBE.VBProjects.Item("Normal").Name



I get:

Normal



in the immediate window.





the Normal project contains only the following procedure:

Sub try()
MsgBox "check"
End Sub


I've tried opening the Help file about this error but it gives me blank gray
screen without any help in it.



What's the reason for that?



Regards,

Amir.
 
J

Jean-Guy Marcil

Amir was telling us:
Amir nous racontait que :
Hi!



I'm trying to compile a normal.dot project using the following
command:


application.VBE.VBProjects.Item("Normal").MakeCompiledFile

2 comments, one helpful, and the other not so much!

Helpful Comment:

According to help, you need to use "BuildFileName" before you call
"MakeCompiledFile".
So, the following code should work (You need to set a reference to the
"Microsoft Visual Basic for Applications Extensibility 5.3" library).

'_______________________________________
Dim myProject As VBProject

Set myProject = Application.VBE.ActiveVBProject

myProject.BuildFileName = "C:\MyOtherProject.dll"
myProject.MakeCompiledFile
'_______________________________________

Not so helpful comment:

The above code still generates the same error you saw and I do not know
why... Maybe it has to do with the type of project? Maybe we need a Class
Module first?
I Googled it up for a while and only found references to the fact that it
does not work (except for the links that were in Russian, Japanese or
German, which I do not read!) and obviously nobody had a solution.

I have always heard that if you want to make a DLL, you have to go through
Visual Studio... but if you find a way to make "MakeCompiledFile" work, do
let us know!

Good luck!
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

Amir

Hi,

'Compile Normal' works just fine but not if I try to run that line in the
immediate.
It also doesn't work if I put that line in another procedure and call that
procedure.

Regards,
Amir.
 
A

Amir

Hi there,

Actually what I'm trying to do is not to compile a dll but to import a
module, then compile it, and save the template.

I want to do so as part of 'Installation' Macro I am preparing. The purpose
is to make an installation document which will install other modules and
forms, and create command bars.

This is because I don't want users to start importing modules and forms
themselves. I want to do that 'programatically' by asking them to open a
Word document which in it's Open event will import all the required modules,
forms and build the command bars. Therefore I assume that I need to compile
the modules I import using that installation macro...

Can you think of a better way of doing that kind of installation?
I can't understand why it has to be so compliacted.

I already have the code making the command bars.

Why users can't just disable security restrictions, then click 'setup.exe'
or open some file to have all the command bars, modules and forms working in
the Normal.dot template?

How can I afford them a simple way to install that set of modules, forms and
command bars I need?

Thanks for your help.
 
J

Jean-Guy Marcil

Amir was telling us:
Amir nous racontait que :
Hi there,

Actually what I'm trying to do is not to compile a dll but to import a
module, then compile it, and save the template.

I want to do so as part of 'Installation' Macro I am preparing. The
purpose is to make an installation document which will install other
modules and forms, and create command bars.

This is because I don't want users to start importing modules and
forms themselves. I want to do that 'programatically' by asking them
to open a Word document which in it's Open event will import all the
required modules, forms and build the command bars. Therefore I
assume that I need to compile the modules I import using that
installation macro...

In such a case, I do not think that you would need to force a "compile". The
code is compiled every time it is run...
Can you think of a better way of doing that kind of installation?
I can't understand why it has to be so compliacted.

It is not complicated, you are making it so :)
I already have the code making the command bars.

Why users can't just disable security restrictions, then click
'setup.exe' or open some file to have all the command bars, modules
and forms working in the Normal.dot template?

How can I afford them a simple way to install that set of modules,
forms and command bars I need?

Thanks for your help.

It seems to me that all you need to do is provide a global template so that
all your forms and command bars will be automatically available whenever a
Word session is started. You do not really want to go to all the this
trouble to import your stuff in the user's Normal.dot. Global templates are
much safer.
Store the template in the start-up folder (Tools > Options > File Locations
Start-up folder).

It is easy enough to figure out that folder by reading the registry, or even
by starting a dummy Word session. Then install the folder in that folder.

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

Amir

Hi!

I've tried that one and it works fine, so i've wrote a little code which
will copy the template into the startup folder.
I put that code in the Open event of another document so that when user
opens the document, template is copied to the startup folder. This works
just fine, but I have another question:
If I want to delete the file of the template which is in the startup folder
using document's open event, I get an error message since it's already
opened.

How can I check if a specific template (named "SmartMenu.dot", that's the
template which is in the startup folder) is currently loaded, and if so,
unload it so that I can delete it's file in the startup folder?

I'm using the following code from an "installation" document (not template)
to delete the template's file, but as i've written, it's not possible
because the file I want to delete is already in use since it's automatically
loaded each time Word starts:

If (Dir(Application.StartupPath & "\" & strFileName) <> "") Then Kill
Application.StartupPath & "\" & strFileName

I prefer not to use command line parameter (/a) to do that, unless there is
a way of running WinWord from a .bat file WITHOUT knowing the exact path of
WinWord.exe.

Thanks!
 
J

Jean-Guy Marcil

Amir was telling us:
Amir nous racontait que :
Hi!

I've tried that one and it works fine, so i've wrote a little code
which will copy the template into the startup folder.
I put that code in the Open event of another document so that when
user opens the document, template is copied to the startup folder.
This works just fine, but I have another question:
If I want to delete the file of the template which is in the startup
folder using document's open event, I get an error message since it's
already opened.

How can I check if a specific template (named "SmartMenu.dot", that's
the template which is in the startup folder) is currently loaded, and
if so, unload it so that I can delete it's file in the startup folder?

AddIns("SmartMenu.dot").Installed = False


But of course, you should include code to make sure it is loaded first:

'_______________________________________
Dim myAddin As AddIn

For Each myAddin In AddIns
If myAddin.Name = "SmartMenu.dot" Then
myAddin.Installed = False
Exit For
End If
Next
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

Amir

Hi,

That's exactly what I was looking for!

Thank you very much !!!

Kind Regards,
Amir.
 

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