RTE '10' This array is fixed or temporarily locked.

G

Gregory K. Maxey

Hello,

I keep getting a runtime error (RTE '10' This array is fixxed or temporarily
locked). Whenever one of my macros tries to run the line:

ActiveWindow.Close wdDoNotSaveChanges

I can't figure out what is causing this arror and I am unable to trap or
bypass the error.

Yesterday I created a relatively crude Word2007 Addin that adds a Tab to the
Ribbon for creating new documents based on a template selected from a
dropdown. Each of the templates (unique files in themselves) has a AutoNew
macro which creates a userform for initial data. Each userform has a cancel
button which contains the lines:

Unload Me
ActiveWindow.Close wdDoNotSaveChanges

With this "crude" template everything works and I have no errors.

Today I have modified the basic AddIn to look in a specified directory for
..dotm, dotx, or .dot files and build a dynamic dropdown that list all
templates in a spedified directory. The template names are stored in an
array an the array is used to label the dropdown list members and passed as
a varialbe to the procedure that creates then new document. Again,
everything works fine until I use the Cancel button on one of the template
Userforms. When I do, I get a Runtime Error 10 This array is fixed or
temporarily locked. When I attempt to debug the line:

AcitveWindow.Close DoNotSaveChanges is highlighted.

I am including the code for both the working and non-working addin. If
anyone is interested I can e-mail both Addins. Thanks.



Working AddIn:

In a standard module "Main" I have a

Option Explicit
Sub Macro1()
Documents.Add Template:="G:\Global Templates 2007\2007 Templates\Attendance
Note (Legal).dotm"
End Sub

Sub Macro2()
Documents.Add Template:="G:\Global Templates 2007\2007 Templates\Fax
(Legal).dotm"
End Sub

Sub Macro3()
Documents.Add Template:="G:\Global Templates 2007\2007
Templates\Letterhead.dotm"
End Sub

Sub Macro4()
Documents.Add Template:="G:\Global Templates 2007\2007 Templates\Memo
(Legal).dotm"
End Sub

Sub Macro5()
Documents.Add Template:="G:\Global Templates 2007\2007 Templates\With
Compliments.dotm"
End Sub

In a UserForm I have:

Option Explicit
Private myRibbon As IRibbonUI

Sub Onload(ribbon As IRibbonUI)
Set myRibbon = ribbon
End Sub

Sub GetDDIndex(ByVal control As IRibbonControl, selectedID As String,
selectedIndex As Integer)
On Error GoTo Err_Handler
myRibbon.Invalidate
Select Case selectedIndex
Case 0
Macros.Macro1
Case 1
Macros.Macro2
Case 2
Macros.Macro3
Case 3
Macros.Macro4
Case 4
Macros.Macro5
End Select
Exit Sub
Err_Handler:
MsgBox "The Ribbon failed to validate. Please close and restart Word to
revaligate the Ribbon", vbCritical + vbOKOnly, "Invalid Ribbon Refresh"
End Sub

Sub GetDDCount(ByVal control As IRibbonControl, ByRef count)
count = 5
End Sub

Sub GetDDLabels(ByVal control As IRibbonControl, index As Integer, ByRef
label)
Dim i As Long
For i = 0 To index
label = Choose(i + 1, "Attendance Note", "Letterhead", "FAX Cover",
"Memorandum", "With Compliments")
Next i
End Sub



Non Working AddIN



Option Explicit

Sub NewDoc(pName As String)

Documents.Add Template:=Path & pName

End Sub

Function Path() As String

Path = Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)

Path = Path & "\2007 Templates\"

End Function



Option Explicit

Private myRibbon As IRibbonUI

Private myArray() As String

Sub Onload(ribbon As IRibbonUI)

Set myRibbon = ribbon

End Sub

Sub GetDDIndex(ByVal control As IRibbonControl, selectedID As String, _

selectedIndex As Integer)

myRibbon.Invalidate

Main.NewDoc myArray(selectedIndex)

End Sub

Sub GetDDCount(ByVal control As IRibbonControl, ByRef count)

Dim myfile As String

ReDim myArray(0)

myfile = Dir$(Application.Options.DefaultFilePath(wdWorkgroupTemplatesPath)
& "\2007 Templates\*.*")

While myfile <> ""

Select Case Right(myfile, 4)

Case Is = ".dot", "dotx", "dotm", ".DOT", "DOTM", "DOTX"

myArray(UBound(myArray)) = myfile

ReDim Preserve myArray(UBound(myArray) + 1)

End Select

myfile = Dir$()

Wend

count = UBound(myArray) '+ 1

End Sub

Sub GetDDLabels(ByVal control As IRibbonControl, _

index As Integer, ByRef label)

Dim i As Long

For i = 0 To index

label = myArray(i)

Next i

End Sub
 
G

Gregory K. Maxey

I still don't know why, but apparently the problem is rooted in the array I
used in the AddIn that populated the dropdown list. I modified the code in
the AddIn to use a Collection instead of an array and it seems to be
working. The code in the AddIn that is now working is shown below.

I would appreciate if someone can help me understand why the problem
persists when using an array and any comments on a better way to do this
task. Perhaps a "Class" module but I don't know much about those.

Thanks.

Option Explicit
Private myRibbon As IRibbonUI
Dim colTemplateList As New Collection
Sub Onload(ribbon As IRibbonUI)
Set myRibbon = ribbon
End Sub
Sub GetDDIndex(ByVal control As IRibbonControl, selectedID As String, _
selectedIndex As Integer)
myRibbon.Invalidate
Set colTemplateList = ListOfTemplates '***
Main.NewDoc colTemplateList(selectedIndex + 1) '***
End Sub
Sub GetDDCount(ByVal control As IRibbonControl, ByRef count)
count = ListOfTemplates.count
End Sub
Sub GetDDLabels(ByVal control As IRibbonControl, _
index As Integer, ByRef label)
Set colTemplateList = ListOfTemplates '***
label = colTemplateList(index + 1) '***
End Sub
Function ListOfTemplates() As Collection
Dim myfile As String
Set ListOfTemplates = New Collection
myfile = Dir$(Application.Options.DefaultFilePath(wdUserTemplatesPath) &
"\*.*")
While myfile <> ""
Select Case Right(myfile, 4)
Case Is = ".dot", "dotx", "dotm", ".DOT", "DOTM", "DOTX"
ListOfTemplates.Add Item:=myfile
End Select
myfile = Dir$()
Wend
End Function
 
J

Jen

I'm interested Greg. (e-mail address removed)

I want to expand my dynamic workgroup template to specific directories. Not
sure I'll be much help though.
 

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