Understanding Macros

G

Guest

Word 2003. Every time I run into a Word glitch, I'm directed towards macros.
I've been to the mvp site over and over. I simply do not understand macros at
all. I don't understand how to create one, how to run one, what all that
"stuff" means, etc. I have tried numerous times and end up shutting
everything down in total frustration. I gladly do the repetitive tasks that
macros are supposed to streamline because it's easier than trying to figure
out macros!

But now I HAVE to figure them out -- I'm creating a large series of locked
forms templates that will need to be spellchecked after data entry and I
can't find a workaround.

I want to do a continuing ed class on this, but in the interim can anyone
recommend a book that offers REALLY simple, step-by-step explanations of
macros? I'm stressing REALLY SIMPLE here! I checked my local library for
"Macros for Dummies" but got no hits. I appreciate any direction anyone can
give. Thank you!
 
C

Charles Kenyon

http://word.mvps.org/FAQs/MacrosVBA/VBABasicsIn15Mins.htm
http://word.mvps.org/FAQs/MacrosVBA/CreateAMacro.htm
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
G

Guest

Thank you both for your suggestions. I do appreciate it. After spending three
hours going over the documents, I'm as confused as ever. At this point, I
don't have time to understand macros anymore. I just have to be able to
spellcheck this protected template and the resulting documents. So I decided
to just paste the code from the mvp document and figure our macros later,
figuring how hard could that be, right?

I follow the steps, I paste everything from the words "Option Explicit"
until I get to "End Sub" right above the word Notes, because I'm assuming I'm
supposed to put all of this information in. I save and close everything down.
I open the template, go to Tools, Macro, Macros, click Run. The (Code) window
opens again in Visual Basic and I get this window: Compile error: Invalid
inside procedure. I click on Help and understand absolutely nothing that help
tells me.

I've had someone tell me to explore OpenOffice.org as another way of trying
to get this template to be spellcheckable. Any help anyone could give would
be appreciated!
 
S

Shauna Kelly

Hi MrsMac

I know how frustrating this can be! But from your description, it looks like
you've done everything correctly.

Let's check two things.

First, do Tools, Macro, Macros and click Run. You'll get the same error you
got before. The (Code) window will open again. Now, look through the code.
Are there any lines in red? If so, they're a problem.

If you copied the text straight from the page at
http://word.mvps.org/FAQs/MacrosVBA/SpellcheckProtectDoc.htm, then you will
have copied several horizontal lines on that page. They marked the end of
one procedure and the beginning of the next. But they're just
window-dressing for the web page. So you may have several lines that look
like -------------- in red. If so, delete those lines.

Does it work OK now?

If not, have a look through the code. You'll see that some is in green
(they're comments). And some is in black (that's the code that runs). Is
there any text in red? If so, it's an error of some kind. If so, post back
and copy the red bits into your message, so we can see what's going wrong.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
G

Guest

Hi Shauna,
Thanks for your reply. I did as you suggested, and did find red dashes,
which I deleted. Ran it again, got the same error, and it tells me that the
"Option Explicit" statement appears in a procedure and must be placed at the
module level. The farther I go, the loster I get! :)

I have many other questions regarding this whole issue, but I will take it
one step at a time! Thank you again for your assistance.
 
S

Shauna Kelly

Hi MrsMac

OK, for the moment, just delete the line that says "Option Explicit". Then
try again.

As a bit of background, the Option Explicit line is not absolutely essential
to running the macro. But it is good practice to use it when writing a
macro, because it forces the developer to explicitly declare all variables.
If that doesn't make much sense to you now, that's OK, but one day it will!

Specifically, there should be one Option Explicit line in the whole module
(ie the whole kind of 'page' of macros), and it must be the very first line
in that module.

But the macro will run without it, so for your purposes today, I'd suggest
deleting it.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
G

Guest

Hi Shauna,
I'm sorry it has taken me several days to get back to this -- abscessed
tooth -- ouch! Thank you so much for helping me with this -- I am so lost.
Okay, I deleted the "Option Explicit" line, ran again. Came back with another
error saying I had to add "End Sub" right before "Sub RunSpellcheck( )". So I
typed this in and no more errors. Yaay! Little victories! I then locked the
template and closed it down.

So I have the macro in there. I tried creating a new document and typing
errors in it, and I can't spellcheck it. I'm guessing this is where I have to
put the button on the toolbar or something to run it? On the template or the
new document? I'm sorry, I really need step-by-step help here because I don't
understand what I'm doing. I so appreciate your assistance!
 
S

Shauna Kelly

Hi MrsMac

I'm really glad to hear that your code is now working.

I'm assuming you put the VBA macro code into your forms template. And since
this is a form, I'm assuming that you're going to be sending it to other
people to use.

There are several ways to go about invoking your new macro. Here is one
relatively simple way.

Do File > Open and open the template. Unprotect it. Do Tools > Customize. On
the Toolbars tab, click New. Choose an appropriate name for the toolbar
(something that refers to the name of the form would be good). And tell the
little dialog box to save this new toolbar in your template (not
Normal.dot!).

Now, still in the Customize dialog, on the Commands tab, in the Categories
list, find Macros. In the right, in the Commands list, you'll see your macro
listed. Specifically, you're looking for RunSpellcheck. Drag that name to
your new toolbar. That will put a button on the toolbar that will invoke
your macro.

By default, the text on the button will be the name of the macro. If you
don't like that, right-click your new button (while the Customize dialog is
still open), and change the name. Play around with all the other options on
that right-click menu while you're there. If you make a complete mess, you
can just drag the button off the toolbar into mid-air to delete it, and then
start again.

If you decide you want an icon on your button, you can choose one from that
right click menu by using "Change button image". But the images there aren't
anything to write home about. Or you could use Edit Button Image, and create
your own. Or, you could pinch the existing spelling icon and copy that to
your new button if you like. The Customize dialog is still open, right? So
click Tools, then right-click Spelling and Grammar, copy that image. Back on
your own new button, right-click and choose Paste Button Image.

In any case, when you're finished, close the Customize dialog and save your
template.

The toolbar will be saved with the template, so if you distribute it to
others, it will go with the template.

Try it out by creating a new document, entering some text in, say, a form
field, and then clicking your new buttton.

There's more info, and screen shots showing some of the steps above at
http://word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
G

Guest

Hi Shauna,
Finally able to look at this again. Followed the steps that you outlined,
everything worked great and was very explicit -- Thank you! Unfortunately, it
doesn't work.

I'm wondering if this is my problem: I HAVE to have the new document locked
so that my client can tab from field to field without messing up the design
of the form. It seems that when I lock the document, the spellcheck protected
document doesn't work. I have the spellcheck icon on the new toolbar, and it
is available, but when I click it nothing happens.

I am so lost!! And so frustrated. Perhaps Word is not the program I need to
be using to accomplish this task?

Any further info you can give me is greatly appreciated!

Mrsmac
 
C

Charles Kenyon

Hi,

No, the idea of the macro is that with it you can spell check a document
when it is protected. The macro unprotects the document and checks the
areas that are subject to change, lets the user make corrections, and then
reprotects the document.

My guess is that somehow your macro did not attach to the button on your
toolbar. Try customizing again, making sure that the customizations go to
your template and not to normal.dot. You might want to also use the keyboard
button on the customize dialog to assign your macro to the F7 key. If you do
this, make sure that the place the keyboard shortcut is saved is also your
template.

You are 95% of the way there and have done the hardest part. Just keep
plugging.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
C

Charles Kenyon

Word has Fill-In fields and Ask fields which fulfill this function, but
spend the time learning Word before you start creating complex templates. It
will save you a lot of time and grief. However, I got caught up in giving
you the information I think you need rather than the answer to your
question. You can find a short tutorial set of documents on my website about
Ask and Fill-In fields. http://addbalance.com/word/download.htm
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
S

Shauna Kelly

Hi MrsMac

As Charles said, you're so close to the end: it will be worth it when you've
finished, so don't give up now.

Just to draw the big picture, in case that helps:

You're producing a template, and you are going to send that template to your
client.

The template must therefore include everything the client needs. That
includes three things:
- the text and form fields and other content that you have typed into the
template
- the macros
- the toolbar, with its button, which runs the main macro.

Before you send the client the template, you will protect it. So the client
will have a protected document, and can tab from field to field. And the
client can spell check the document by clicking on your button on your
toolbar.

So let's make sure that they're all together in the template.

Do File > Open and open your template.
- Obviously you can see your text and formfields and other content. So
that's OK.

- Do Alt-F11 to open up the macros. Find your macros and click in one so the
code of the macro is displayed. On the left of the screen, you should see a
panel that looks a bit like Windows Explorer. It will list the names of
every open document plus any add-ins you have running. The name of the
module holding your macros (probably "Module1" or some such, unless you
re-named it), will be shaded in grey. It indicates the currently-open
module. The crucial question is this: does the layout indicate that the grey
shaded module is within your template? If so, cool. Do File > Close and
return to Word. If not, write back and let us know.

- Back in Word, do Tools > Templates and Add-ins. Click the Organizer
button. The left-hand pane should refer to your document. Click on the
Toolbars tab. Do you see your toolbar listed? If so, cool. Close down that
dialog box. If not, then the toolbar wasn't saved in your template. Write
back and let us know.

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 
G

Guest

I feel like I'm in a neverending nightmare! I am going to try and spell
everything out in the hopes that you can see something that I'll never see in
this mess.

I have the newly created macro toolbar on the template. There are two
buttons on it -- one called "RunSpellcheck" and one called
"SpellcheckProtectedDocument." I'm not sure why there are two, but these were
both there and since I have no idea what the difference is between them or
which one to use, I put them both on.

When I open a new document based on the template, the Forms toolbar is there
and the new macro toolbar is there with both buttons on it. I type in some
misspelled words and click on the RunSpellcheck icon. I get: "Compile error:
Sub or Function Not Defined" and this line is highlighted: Call
TurnNoProofingOff (fmFld). I close these windows down, stopping the debugger
(whatever that is) and go back to my document, which is now unprotected and
has the red squigglies under the misspelled words. I click on the
"SpellcheckProtectedDocument", hoping that will do something, but as in the
past nothing happens.

So now I shut everything down and go back and open the template and try to
follow Shauna's steps from her 3/25 response. I open the template, I see the
text and formfields. I hit Alt-F11 to open up the macros. I get a new window
entitled "MacroPractice (name of the template) - NewMacros (Code)" Then I
see:

Sub SpellcheckProtected Doc ()
Dim Cancelled As Boolean, MyRange As Range,
CorrectedError As String, oDoc As Document
End Sub
____________________________________________
Sub Run Spellcheck ()
etc. etc.

There is no panel on the left of the screen that opens that looks like
Windows Explorer. All I have is the main window entitled Microsoft Visual
Basic - MacroPractice, and then a sub window that says MacroPractice -
NewMacros (Code).

I went to Tools > Templates > Add-ins. The toolbar is listed for the
MacroPractice template.
 
G

Greg

A nightmare no, but maybe sometimes it is easier to just be given the
fish ;-)

Send me an e-mail and I will send you a template with the spellcheck
macros complete.

(e-mail address removed)

You will need to turn that address around.
 
G

Guest

Thank you for responding, Greg. I will send you an e-mail. While I need to be
"given the fish" to get this project closer to completion for my client, I
would appreciate hearing from others as to what I did wrong.

I apologize for venting my frustration -- I have never had so much trouble
trying to accomplish a task or learn how to do something in Word before. And
the sad thing is, my understanding of writing / recording / using macros is
no better now than it was when I started a month ago. However, I have printed
out at least four different documents from the MVP site and from Graham's
site, and once the dust settles and I get these templates created, I will go
through them step by step and see if I can bring myself closer to
understanding macros. I guess a good book on VB couldn't hurt either.

Thank you for your help !
 
G

Guest

I have been following all of your responses on the enabling spell check in a
template as I have been trying to do the same thing. I want you to know I
followed all of your responses and my spell check is working in my template.
Thank you both!
 
G

Guest

Hi Dwoods,
I am very happy for you! Perhaps you see something that I have done wrong? I
would appreciate hearing from anyone out there who can pinpoint where I went
wrong in my steps. Thank you!
 

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