PDA

View Full Version : Solved: Can't find Macro



RECrerar
10-04-2007, 07:50 AM
Hi again.

I have my macro in a module in a document which is open, however when I press Alt F8 to get a list of available macros it isn't in the list.

I had this probelem before and it was due to my security settings being too high, but I selected enable macros when the document was opened, so am not sure what is casueing the problem now.

Any sugegstions?

(The macro is desigened to be run on any document except the one it is written in)

Charlize
10-04-2007, 07:53 AM
Maybe you usedoption private modulewhich hides all macros in that module (if you know the name, you can still type them in).

RECrerar
10-04-2007, 07:53 AM
Hmm okay well the process of leaving the computer, making a cup of tea and submitting a post on the problem appears to have fixed the problem.

So I am good, but if anyone can explain why it may not have been working before I would still be interested to hear for future reference

lucas
10-04-2007, 08:05 AM
Hi RECrerar,
Post your file please so we can take a look at it.

RECrerar
10-04-2007, 08:09 AM
Okay here is the file (it's a very simple macro)

lucas
10-04-2007, 08:30 AM
Appears to be an error that I get myself frequently....picnic error. Problem in chair not in computer

RECrerar
10-05-2007, 01:42 AM
Hi again, still having the same probelem as yesterday. The macro, noe slightly modified to allow to user to specifiy the save directory (thanks Lucas) can be seen and run on the document it is writen in but is not recognised if a different document is the active document.

Any more ideas on what i've done? i'm assuming it must be a settings issue somewhere.

RECrerar
10-05-2007, 02:57 AM
So if I want a macro in word to be available in all documents do I have to do it in the 'Normal'? I want the macro to be able to be used as an Add-In (or the word equivalent) where the document containing the macro can be stored in a network drive and used by anyone with access to that drive.

fumei
10-05-2007, 04:00 AM
I think you need to do some reading up and research.

"can be seen and run on the document it is writen in but is not recognised if a different document is the active document."

Yup. That is the way it works.

Code in a document runs from that document.

Code in a template runs from any document created from that template.

Code in a template loaded as a global template can be run from any document.

Do you have to do it in Normal"? NO! In fact, it is a bad idea to have it in Normal.

RECrerar
10-05-2007, 04:09 AM
Okay, I have an update on the situation.

First of all I would like to point out that most of my work is done using Excel and I really am not very up on Word VBA hence any previous/future misunderstandings on how the word VBA works.

I have been looking at posts and following links and think I have a clearer general idea of how the program should work, but am not sure on the details.

I would like the Program to be launched automatically when word is opened and have a menu item, probably attached to the tools menu that will run the macro. This should be able to easily be added to multiple computers.

I belive to do this I have to save it as a template (.dot) and that if I want it to launch whenever word is opened it must be saved in the word start up folder

For anything to work when Word is opened it has to in a global template. Either normal.dot, or a template (.DOT) file that is in the Startup folder.

There are two Startup folders. One for the username session, and one for the machine session.

Username session Startup is Document and Settings/username/Application Data/yaddaydda/Startup.

Machine session is Program Files/Office/yaddayadda/Startup.

That is it. There is no other way to get an procedure to execute on Word startup. There IS a way for a specific file opening, using Document_Open.(fumei, from this thread http://vbaexpress.com/forum/showthread.php?t=14678&highlight=custom+menu

(I think that all the information i need muct be in this tread, but was finding it a bit hard to follow, am gonna try printing it out and reading a hard copy form and going through it slowly after lunch.)

So the reason that I couldn't get my macro to run on a different document is that it is saved as a .doc not a .dot, is this correct?

If I save it as a .dot in one of the locations above it should load whenever word does, is this correct?

Next part of the question.

The code below is the Excel equivalent of what i want to do in word, I found an example of adding tool bars but would rather have it as a menu item, so was wondering if someone could let me know how I change the code so that it will work in word.
(The code was copired from word, where it doesn't work)


Option Explicit
Dim Convert As CommandBarControl
Const MenuItem1 = "Convert to .txt..."
Const MenuMacro1 = "OpenWordDoc"
Dim msg As String

Private Sub Document_Close()
' Delete the menu Item
On Error Resume Next
Application.CommandBars(1).Controls("Tools").Controls(MenuItem1).Delete
On Error GoTo 0
End Sub


Private Sub Document_Open()

'Add a menu Item to the Tools Menu

' Delete existing Item just in case
On Error Resume Next
Application.CommandBars(1).Controls("Tools").Controls(MenuItem1).Delete
' Set up Error trapping
On Error GoTo NoCanDo

' Create New Menu Items
Set Convert = Application.CommandBars(1).Controls("Tools").Controls.Add
Convert.Caption = MenuItem1
Convert.OnAction = MenuMacro1
Convert.BeginGroup = True
Exit Sub
NoCanDo:
msg = "An error occurred" & vbNewLine
msg = msg & MenuItem1
msg = msg & " was not added to the Tools menu."
MsgBox msg, vbCritical
End Sub

Right that will do for now, about to attempt the whole template thing now. if you could let me know if my understanding is correct and also how I modify the above code for word it would be appreciated.

RECrerar
10-05-2007, 04:10 AM
Oh thanks fumei, spent so long writing that post that you have already answered most of it.

fumei
10-05-2007, 04:19 AM
If you have a question re: commandbars, it really should go into its own thread.

RECrerar
10-05-2007, 04:27 AM
Fair enough, will put it in a different thread though, just figured it was all kinda part of the same problem.

Was hoping you would be able to elaborate on your direction to the program start up folders, particuarly where the "yaddayaddayadda" takes you.

I have tried to save it as a .doc and the default location it suggests is:

WINNT/Profiles/username/applicationdata/microsoft/templates which appears to be where the normal.dot is. I can't however locate any folder called 'Startup' and the template doesn't seem to load automatically, so i'm assuming its in the wrong place.

the other location I tried was programfiles/microsoftoffice/Templates, but this clearly seems wrong.

So where exactly am I meant to save it?

RECrerar
10-05-2007, 04:51 AM
Just to say I found the startup folder at: Programfiles/microsoftoffice/office10/startup

Macro loads automatically now, will check out menu items for a bit and if still stuck will post in a new thread. thanks to everyone for their help