Alllowed volume for a macro

J

jjohanss

I am a freelance translator, and tried recently to create a macro to
"find-and-replace" words which often are found in an English text.
After having made the macro I tried to register it, and was told that
it was too big. Is that a message for one macro or is Word calculating
the total volume of all the macros in the registery, In other words;
can I make ten macros with 100 words in each, or will Word add them
up. And where do I find information telling me the limit for one - or
alle - macro(s)?

Jan J.
 
G

Graham Mayor

Without seeing your code I suspect the problem is with the total macro size.
If you have 100 replacement fuctions in a macro it will be a monstrosity. It
would be better to use a look-up table to store your words and their
replacements e.g. the following will replace all the words from the left
column of a table with those from the right column. The table document is
identified by the path highlighted.


Sub ReplaceFromTableList()
Dim ChangeDoc As Document
Dim RefDoc As Document
Dim cTable As Table
Dim oFindText As Range
Dim oReplaceText As Range
Dim i As Long
Dim sFname As String
'**************************
sFname = "D:\My Documents\Test\changes.doc"
'**************************
Set RefDoc = ActiveDocument
Set ChangeDoc = Documents.Open(sFname)
Set cTable = ChangeDoc.Tables(1)
RefDoc.Activate
For i = 1 To cTable.Rows.Count
Set oFindText = cTable.Cell(i, 1).Range
oFindText.End = oFindText.End - 1
Set oReplaceText = cTable.Cell(i, 2).Range
oReplaceText.End = oReplaceText.End - 1
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findText:=oFindText, _
ReplaceWith:=oReplaceText, _
Replace:=wdReplaceAll, _
MatchWholeWord:=True, _
MatchWildcards:=False, _
Forward:=True, _
Wrap:=wdFindContinue
End With
End With
Next i
ChangeDoc.Close wdDoNotSaveChanges
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
F

Fumei2 via OfficeKB.com

Definitely do some sort of look up, keeping the actual words NOT hard-coded
in your macro (procedure). There is (although I do not know if that still is
the case with 2007) a limit of 64 K, and I believe it is for a code module.
As these are plain-text really, 64 K is a LOT. It takes a monster of a code
procedure to hit that wall. A version of what Graham posted should do the
trick.
 

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