View Single Post
  #14   Report Post  
Posted to microsoft.public.word.docmanagement
MrsMac
 
Posts: n/a
Default Understanding Macros

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.








"Shauna Kelly" wrote:

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


"MrsMac" wrote in message
...
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



"Shauna Kelly" wrote:

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/Customizat...oToToolbar.htm

Hope this helps.

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


"MrsMac" wrote in message
...
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!


"Shauna Kelly" wrote:

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


"MrsMac" wrote in message
...
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.


"Shauna Kelly" wrote:

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/...ProtectDoc.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


"MrsMac" wrote in message
...
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?