Word 2004 error on MVP macro script

R

Rudy Kohut

I have been trying to get the following script to work in Word 2004 (V
11.1). It comes from the Word MVP site and the article is titled: "Enable a
user to double-click text in a document to change its value".

The script is:

Sub SymbolCarousel()

Select Case Selection.Fields(1).Code.Characters(29)
  Case "Y"
    Selection.Fields(1).Code.Characters(29) = "N"
  Case "N"
    Selection.Fields(1).Code.Characters(29) = "?"
  Case "?"
    Selection.Fields(1).Code.Characters(29) = "Y"
  Case Else
End Select

End Sub

When I run this in Word 2004 by double clicking on the field { MACROBUTTON
SymbolCarousel N}, I get a "compile" error message "sub or function not
defined" and the debugger opens with the word "Characters" (in the second
line with that word in it), highlighted.

Any help sorting out why this is happening would be appreciated.

Cheers

Rudy
 
J

John McGhie

Hi Rudy:

The problem is that you have pasted the code into the VBA Editor.

When you paste from Safari you paste "non-breaking" spaces in any run of two
or more spaces. On the PC, the VBA editor converts them into ordinary
spaces.

Remove the spaces in front of the Case statements and the Selection
statements. Then use Debug>Compile to check. It should now compile
correctly.

Cheers


Sub SymbolCarousel()

Select Case Selection.Fields(1).Code.Characters(29)
  Case "Y"
    Selection.Fields(1).Code.Characters(29) = "N"
  Case "N"
    Selection.Fields(1).Code.Characters(29) = "?"
  Case "?"
    Selection.Fields(1).Code.Characters(29) = "Y"
  Case Else
End Select

End Sub

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 
P

Paul Berkowitz

Another, less tedious, way to avoid this problem is to use a newsreader such
as Entourage rather than the web for reading newsgroups. Code, or any text,
pasted from Entourage or a dedicated newsreader will not have these
non-breaking spaces - they'll be regular text and regular spaces. Not only
that, but your news messages will reach the news server and be propagated
back out again within minutes - or seconds - rather than hours.


To access newsgroups in Entourage, click on the Microsoft News Server in
Entourage's Folder List, filter for mac.office (not the reverse, which gets
you deprecated newsgroups). Command-click to select

microsoft.public.mac.office.word

and any others you want. Then click Subscribe button. Then click on the
newsgroup itself, now just below the Microsoft News Server icon in Folders
List.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.
 
J

John McGhie

All:

In yesterday's post, I forgot to attribute the REAL source of the
intelligence and ingenuity: J. E. McGimpsey was the one who discovered this
problem and put me onto it.

For a moment there, I was looking really clever. Sorry people, it was all
the work of the "other" John...

In this case, the reason the poster had the problem is because he pasted the
code from a web site. A website I know quite well. Because I am one of the
people who maintains it...

J.E. And I have been having some discussions behind the scenes as to how to
recode the VBA samples on that website so that the problem does not occur.
It's a very recent issue: and doesn't occur of you paste the code on the PC.
There's something about Mac Office or OS X that has changed to cause the
spaces to come through as non-breaking spaces on the Mac.

Many new computer users do not understand that a "space" is not a "nothing".
It's a character, like any other. The only difference is that a space
character prints all white: but print it indeed does! A non-breaking space
is a different "character" from a space. And the VBA editor in Word Mac
doesn't understand that it's a "space", not a "piece of code".

Cheers


Another, less tedious, way to avoid this problem is to use a newsreader such
as Entourage rather than the web for reading newsgroups. Code, or any text,
pasted from Entourage or a dedicated newsreader will not have these
non-breaking spaces - they'll be regular text and regular spaces. Not only
that, but your news messages will reach the news server and be propagated
back out again within minutes - or seconds - rather than hours.


To access newsgroups in Entourage, click on the Microsoft News Server in
Entourage's Folder List, filter for mac.office (not the reverse, which gets
you deprecated newsgroups). Command-click to select

microsoft.public.mac.office.word

and any others you want. Then click Subscribe button. Then click on the
newsgroup itself, now just below the Microsoft News Server icon in Folders
List.

--

Please reply to the newsgroup to maintain the thread. Please do not email
me unless I ask you to.

John McGhie <[email protected]>
Consultant Technical Writer
Sydney, Australia +61 4 1209 1410
 

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