Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling a central macro 1

Status
Not open for further replies.

DeSn

Programmer
Nov 20, 2001
111
BE
Hi,

Is it possible to create a macro (actually a function) and place it somewhere (i suppose in a dummy word document) so it can be called by several different macros from other word document?

 
yes.

For small things you can place it on normal.dot.
For big things I would create a new document just for that and I would place a reference to it on the normal.dot.


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
I would rather have a few lines stored somewhere and have them automaticly copy/paste in all of my word document and then interprete them. SO i can put the following code in a central "function".

ActiveDocument.PrintOut Background:=False
ActiveDocument.SaveAs FileName:=fichsave, _
FileFormat:=wdFormatDocument, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=False, SaveAsAOCELetter:=False
ActiveWindow.Close

Is this possible?
 
NO.
You need to have a macro built and saved on one document.

If needed you can create a add-in with that code and with an associated macro button placed on the toolbar menu to do that.

That's the best you can do.


Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Create a new document ABC
add the following code to it (alt-f11 to open the VBA editor…)

Sub grammar()
ActiveDocument.CheckGrammar
End Sub

Go to the document again,
right-click on the toolbar->customize->toolbar->new

Give the name to the toolbar and make it available to ABC only, not normal.dot

Place this new toolbar on the toolbar group.

Now you need to place a macro button on it.
Still within the customize panel.
select commands->macros
select and drag the macro (grammar) into the new toolbar.
Once there right-click on the new macro name within the toolbar and change it's name to something more user-friendly.
(you can also change the image of the macro if you wish).

Now save this document as a ".dot", and place it within the STARTUP folder of word. (tools->options->file locations->startup)

Now go to tools->templates&add-ins and add the new template to the list.

Close word.
Next time you start you will have a button available on the toolbar with the new macro.


This code is really just an example. You can create almost anything you wish with this method.




Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
I have this code in a certain document

maindoc = ActiveDocument.path & "\" & "maindoc.doc"

Documents.Open FileName:=maindoc, Visible:=False

Application.Run MacroName:=maindoc & "." & "Module1" & "." & "m"

and in maindoc.doc in module1 I have this code:

Sub m()
MsgBox "test"
End Sub

But i get 'Unabled to run this macro'. Anyone?
 
From the help:

Application.Run "Normal.Module1.MAIN"
Application.Run "MyProject.MyModule.MyProcedure"
Application.Run "'My Document.doc'!ThisModule.ThisProcedure"
If you specify the document name, your code can only run macros in documents related to the current context — not just any macro in any document.

What does this means?

 
it works. I've put everything global in a template and added that to my documents (like you said).

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top