Error Condition

B

Bart Teems

I am getting an error condition 'Subscript out of range' - However it is not and can be proven by viewing the subscript (through a msgbbox) right before the error. Also, the error does not occur if the template is loaded manually, but occurs everytime when the template is in the startup directory. Also, the error occurs the first time, but not on subsequent times of running the macro. Also, it occurs on Word 2000, but not Word 2002. But the customer needs it to work on Word 2000

The code is ..

For i = 1 To 1
strFilename = Options.DefaultFilePath(wdUserTemplatesPath) &
Application.PathSeparator & AllTemplates(i
If FileExists(strFilename) The
' Open the Template as a template, Invisible to use
Set TheDoc = Word.Application.Documents.Open(Filename:=strFilename

' Set our variable
SetOptions TheDo

' Save the file in its original file format of templat
TheDoc.Close SaveChanges:=wdSaveChanges, OriginalFormat:=wdOriginalDocumentForma
Els
MsgBox "Could not find:" & strFilename & vbCrLf & vbCrLf & "No changes made.
lastErrorMsg = "File Not Found:" & strFilename & vbCrL
End I
Nex

And the error occurs on line two where the variable strFilename is being set. When the counter i gets to two, I get the subscript error. But on subsequent runs, it works fine. I have done everything to rearrange this code to make it work, but to no avail. Anybody got any ideas? Thanks for your help, Bart.
 
P

Perry

What happens if you put following statement in the
general declaration section of the codemodule y're
working in:

Option Base 1

Kindy repost if this doesn't remedy.
You'll have to include the code part in which the array AllTemplates()
is populated as well, in such case.

Krgrds,
Perry

Bart Teems said:
I am getting an error condition 'Subscript out of range' - However it is
not and can be proven by viewing the subscript (through a msgbbox) right
before the error. Also, the error does not occur if the template is loaded
manually, but occurs everytime when the template is in the startup
directory. Also, the error occurs the first time, but not on subsequent
times of running the macro. Also, it occurs on Word 2000, but not Word 2002.
But the customer needs it to work on Word 2000.
The code is ...

For i = 1 To 12
strFilename = Options.DefaultFilePath(wdUserTemplatesPath) & _
Application.PathSeparator & AllTemplates(i)
If FileExists(strFilename) Then
' Open the Template as a template, Invisible to user
Set TheDoc = Word.Application.Documents.Open(Filename:=strFilename)

' Set our variables
SetOptions TheDoc

' Save the file in its original file format of template
TheDoc.Close SaveChanges:=wdSaveChanges, OriginalFormat:=wdOriginalDocumentFormat
Else
MsgBox "Could not find:" & strFilename & vbCrLf & vbCrLf & "No changes made."
lastErrorMsg = "File Not Found:" & strFilename & vbCrLf
End If
Next

And the error occurs on line two where the variable strFilename is being
set. When the counter i gets to two, I get the subscript error. But on
subsequent runs, it works fine. I have done everything to rearrange this
code to make it work, but to no avail. Anybody got any ideas? Thanks for
your help, Bart.
 
Top