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
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