View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
NickH NickH is offline
external usenet poster
 
Posts: 60
Default Workbook_Open - AutoCorrect Routine Doesn't Work

I'm using Excel 2003 - SP3

I've written a couple of routines to Add and subsequently Delete a
couple of AutoCorrect entries. The intention was to call the Add
routine from Workbook_Open and the Del routine from
Workbook_BeforeClose.

Both routines work fine when fired from the VBE using F5. The Del
routine also works fine when called from the Workbook_BeforeClose
routine. However, the Add routine is impotent when called from either
the Workbook_Open or Auto_Open routines.

It runs without error, as evidenced by msg boxes but it has no effect
on the ACL. Here's the code for the Add routine - apologies for any
wrap-around...

Public Sub AutoCorrectAdd()
Dim repl() As Variant
Dim x As Long
Dim TLA_used As Boolean
Dim TLAO_used As Boolean

MsgBox "Start of AutoCorrectAdd. Error = " & Err.Number

TLA_used = False
TLAO_used = False

repl = Application.AutoCorrect.ReplacementList

For x = 1 To UBound(repl)
If repl(x, 1) = "TLA" Then TLA_used = True
If repl(x, 1) = "TLAO" Then TLAO_used = True
Next

If Not TLA_used Then _
Application.AutoCorrect.AddReplacement _
What:="TLA", _
Replacement:="Top Level Action Owner"
If Not TLAO_used Then _
Application.AutoCorrect.AddReplacement _
What:="TLAO", _
Replacement:="Top Level Action Owner"
' Yes I do want both TLA and TLAO to mean the same

MsgBox "End of AutoCorrectAdd. Error = " & Err.Number

End Sub

There are a small number of earlier posts regarding this issue and
responses all seem to imply the developer is doing something wrong but
don't manage to pinpoint what. I'm wondering if this could be a
version/update specific problem. Is it possible that Microsoft have
blocked ACL changes by opening routines, to prevent a specific hack?

I guess what I'm asking is - Am I fighting a lost battle or is there a
way round this?