About four years ago I posted a query on EE to ask how, using Word with VBA, I could load strings longer than 255 characters into AutoCorrect. Essentially the solution was convoluted but it worked. For this example, the string to change to the long text is called strShortcut and the text is called strMsg.
(a) Dimension a variable to hold the long message, say “TextToAdd” as a Range
(b) Insert a new table with only one cell at the end of the document; say it is “Tbl3”
(c) Go through a loop to insert the shortcuts and the long texts into AutoCorrect
i. Copy the long string, strMsg, into the table: as in Tbl3.Columns(1).Cells(1).Range = strMsg
ii. Set TextToAdd = Tbl3.Columns(1).Cells(1).Range
iii. Chop off the end of TextToAdd: TextToAdd.End = TextToAdd.End - 1
iv. Add the message into AutoCorrect: AutoCorrect.Entries.AddRichText Name:=strShortcut, Range:=TextToAdd
(d) When the loop is done, delete the table inserted in step (b) above.
Except for one thing, the above works. The problem is that when the computer reaches step (iv) above, it displays a message: “Run-time error ‘-2147467259 (80004005)”. If I ignore that warning, the long message still gets loaded and when the routine is finished, typing the strShortcut string generates the desired message.
Is that error message a time bomb that is going to give me problems later, or can I insert an “On Error Resume Next” to avoid stopping the code?
--JRA in Priddis, Alberta