Macro for inserting numbered equations-error

D

Dave M.

Hi all,

I'm trying to create a macro for inserting numbered equations with
right-justified equation numbers. I just re-installed Office 2004
(updated to 11.3.6) on an Intel Mac (10.4.10). I recorded the macro
by taking the exact steps I use to set the proper style, tab to the
center tab, insert the equation, tab to the right-justified tab,
insert the number (using SEQ eq), hit 'return' and I'm done.

If I do the steps manually, all is well. WHen I try to run the macro,
I get the following error:

"The server application, source file, or item cannot be found. Make
sure the application is properly installed, and that it has not been
deleted, moved, or renamed."

The next box has the following:

"Run-time error '4198': Command failed"

Here is the macro that was recorded. The line that I've spaced out is
the line that the debugger shows as having the error.

Sub Equation()
'
'
Selection.Style = ActiveDocument.Styles("Numbered Equation")
Selection.TypeText Text:=vbTab

(Here is the line that generates the error)
Selection.InlineShapes.AddOLEObject LinkToFile:=False

Selection.TypeText Text:=vbTab & "("
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"SEQ eq", PreserveFormatting:=True
Selection.TypeText Text:=")"
Selection.TypeParagraph
End Sub

If I re-record the macro and leave out that line, everything works.

I use a lot of numbered equations so this is a rather handy macro to
have.

Ideas?

Dave
 
D

Dave M.

Sorry, I'm going to reply to myself here...

The first macro was done by clicking the Equation Editor toolbar
button. The following was recorded using the INSERT-OBJECT-MICROSOFT
EQUATION method. The results were the same.

I have VBA installed from the Office installation, as well as the
Equation Editor.

Sub InsertEquation2()
'
'
Selection.Style = ActiveDocument.Styles("Numbered Equation")
Selection.TypeText Text:=vbTab
Selection.InlineShapes.AddOLEObject ClassType:="Equation.3",
FileName:="", _
LinkToFile:=False, DisplayAsIcon:=False
Selection.TypeText Text:=vbTab & "("
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"SEQ eq", PreserveFormatting:=True
Selection.TypeText Text:=")"
Selection.TypeParagraph
End Sub
 
J

John McGhie

Hi Dave:

In each case, you are adding an equation that doesn't yet exist, so the
macro is blowing up because the equation is empty.

This is not really a macro that you can "Record", you would need to write it
to get it to work.

May I suggest that you simply record the macro that places the correct
number, and use that AFTER you have inserted the equations. In other words,
don't try to record the step that inserts the equation.

You can't record that step anyway, because the equation doesn't exist (or if
it does, you will insert the SAME equation each time the macro runs).

Cheers

Sorry, I'm going to reply to myself here...

The first macro was done by clicking the Equation Editor toolbar
button. The following was recorded using the INSERT-OBJECT-MICROSOFT
EQUATION method. The results were the same.

I have VBA installed from the Office installation, as well as the
Equation Editor.

Sub InsertEquation2()
'
'
Selection.Style = ActiveDocument.Styles("Numbered Equation")
Selection.TypeText Text:=vbTab
Selection.InlineShapes.AddOLEObject ClassType:="Equation.3",
FileName:="", _
LinkToFile:=False, DisplayAsIcon:=False
Selection.TypeText Text:=vbTab & "("
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"SEQ eq", PreserveFormatting:=True
Selection.TypeText Text:=")"
Selection.TypeParagraph
End Sub

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:[email protected]
 
D

Dave M.

Thanks for the reply. If I have to insert some sort of temporary or
"dummy" equation, I'm willing to do that; NeoOffice and OpenOffice
(which I currently use) both do exactly that when using their numbered
equation macro.

Is this phenomonom specific to the Mac version? There are
instructions on the web for doing what I am trying to do but they seem
to be focused on the Windows version:

http://ist.uwaterloo.ca/ec/equations/equation.html

http://www.dessci.com/en/products/ee/ee_tips.htm#eqn_numbers (tips 4
and 5)

By your suggestion, I would have to split the macro into two separate
macros or just do most of the work manually. The reason I say that is
because the line with the equation is also formatted differently than
surrounding text. For the equation line, I set a centering tab at the
center of the two margins and a right-justified tab just before the
right margin.

I see this as the sequence of events:
(1) MACRO: Set tabs, tab over to center tab
MANUAL: Insert desired equation
(2) MACRO: Insert parenthesis, sequence field, close parenthesis,
carriage return, reset tabs to normal style

In any case, I'll give your suggestion a try.

Thanks,
Dave
 
J

John McGhie

Hi Dave:

I would be tempted not to bother with a macro at all.

1) Use a style to set the formatting and tabs. If you set the Equation
style to have a "Style for following paragraph" of "Normal" you won't have
to bother resetting any formatting, just hit Enter at the end of the
caption.

2) Use an AutoText to contain the SEQ field and parentheses. Give it a
short non-word name (e.g. "#nh" for "Number Here"). Whenever you want one
just type "#nh" and hit Space. The name must be a minimum of three
characters: ensure it is not likely to occur as a word or you will get a
number any time you type the word....

There's nothing wrong with the Design Science tip: but it suggests that you
record a macro only to insert the number! They know as well as I do that if
the equation is not there already it will blow up! :)

My suggestion is to use an AutoText. If you do, you can create a dummy
equation, with all of the formatting and styles and numbered caption in
place and just insert the entire thing in one go. You can even assign a
keystroke to it so that you don't have to type anything.

Note: I have not told you how to do this because I want you to read it all
up in the Word help. That will save me pages of typing, and you literally
years of your life, because once you learn to use the Word help your
productivity shoots up. However, if you get stuck with this, by all means
come back and we'll be delighted to help you along.

Microsoft Word is a lot more powerful than either of the other two: it has
an order of magnitude more power tools available when you get serious with
it :)

Cheers

Thanks for the reply. If I have to insert some sort of temporary or
"dummy" equation, I'm willing to do that; NeoOffice and OpenOffice
(which I currently use) both do exactly that when using their numbered
equation macro.

Is this phenomonom specific to the Mac version? There are
instructions on the web for doing what I am trying to do but they seem
to be focused on the Windows version:

http://ist.uwaterloo.ca/ec/equations/equation.html

http://www.dessci.com/en/products/ee/ee_tips.htm#eqn_numbers (tips 4
and 5)

By your suggestion, I would have to split the macro into two separate
macros or just do most of the work manually. The reason I say that is
because the line with the equation is also formatted differently than
surrounding text. For the equation line, I set a centering tab at the
center of the two margins and a right-justified tab just before the
right margin.

I see this as the sequence of events:
(1) MACRO: Set tabs, tab over to center tab
MANUAL: Insert desired equation
(2) MACRO: Insert parenthesis, sequence field, close parenthesis,
carriage return, reset tabs to normal style

In any case, I'll give your suggestion a try.

Thanks,
Dave

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:[email protected]
 
D

Dave M.

Thanks John--I'll have to re-read those two tips, as I thought they
included inserting the blank equation.

As far as Word/OpenOffice/NeoOffice go, I actually migrated AWAY from
Word to boost my productivity; early in my graduate thesis, Word kept
corrupting my documents if I worked on them for more than an hour or
two. I use a lot of inserted equations, charts, spreadsheets, etc.
There's a page at Design Science that details several methods of
working around the problem, but the base problem is that the .doc
format is so bloated that complex documents tend to get corrupted a
bit easily. I found that disappointing, as I had Word set up just the
way I wanted it, with the different text formats, page layouts, etc.
I also preferred Excel, as I could do various linear regressions quite
easily (OpenOffice Calc leave a bit to be desired there).

I've never had such document corruption issues using OpenOffice/
NeoOffice and the ODF format. The .docx OOXML format may be better so
I'm waiting for that to come out; I also hope that somebody writes
some plug-in or add-on for Word for Mac that supports the ODF format
as well.

Dave
 
J

John McGhie

Hi Dave:

Yes, the persistent corruption of complex documents was the reason Microsoft
moved to XML, and XML is a lot more robust.

Of course, people who work in Word all day long can get the previous format
to hang together for months or years of heavy editing of complex documents.
Professional users can do it, but it's unrealistic to expect new users to
work with such a degree of precision.

I believe the ODF Transform is there already, for people who can do without
complex objects. ODF does not support much beyond simple "formatting". It
was intentionally designed as a simple format with a low implementation
cost. OOXML is much richer.

Cheers

Thanks John--I'll have to re-read those two tips, as I thought they
included inserting the blank equation.

As far as Word/OpenOffice/NeoOffice go, I actually migrated AWAY from
Word to boost my productivity; early in my graduate thesis, Word kept
corrupting my documents if I worked on them for more than an hour or
two. I use a lot of inserted equations, charts, spreadsheets, etc.
There's a page at Design Science that details several methods of
working around the problem, but the base problem is that the .doc
format is so bloated that complex documents tend to get corrupted a
bit easily. I found that disappointing, as I had Word set up just the
way I wanted it, with the different text formats, page layouts, etc.
I also preferred Excel, as I could do various linear regressions quite
easily (OpenOffice Calc leave a bit to be desired there).

I've never had such document corruption issues using OpenOffice/
NeoOffice and the ODF format. The .docx OOXML format may be better so
I'm waiting for that to come out; I also hope that somebody writes
some plug-in or add-on for Word for Mac that supports the ODF format
as well.

Dave

--
Don't wait for your answer, click here: http://www.word.mvps.org/

Please reply in the group. Please do NOT email me unless I ask you to.

John McGhie, Consultant Technical Writer
McGhie Information Engineering Pty Ltd
http://jgmcghie.fastmail.com.au/
Sydney, Australia. S33°53'34.20 E151°14'54.50
+61 4 1209 1410, mailto:[email protected]
 

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