View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
BrianB BrianB is offline
external usenet poster
 
Posts: 109
Default open workbook problem

Has the file been saved as a Template with a.xlt suffix instead of .xls ?

Regards
BrianB
=============================================


(Aivars) wrote in message . com...
hello,
Excel 2000 sr-1 sp-3 win2000
Why this simple code what follows opens the
workbook numbering it just as if it was created
from template? 1,2, 3 and so on?
(ThisWorkbook is an add-in in my case)

this code is in fact from Rob Bovey's et al
Excel 2002 VBA programmers reference.


Sub OpenMainSheet()
Dim sFullName As String
Dim stFilename As String
Dim Wkb As Workbook

sFullName = ThisWorkbook.Path & "\Finansu_Parskatu_Formas.xls"
stFilename = GetFileName(sFullName)


If IsWorkbookOpen(stFilename) Then
Set Wkb = Workbooks(stFilename)
Wkb.Activate
Else
Set Wkb = Workbooks.Open(Filename:=sFullName)
End If
End Sub


Function IsWorkbookOpen(stName As String) As Boolean
'IsWorkbookOpen returns True if stName is a member
'of the Workbooks collection. Otherwise, it returns False
'stName must be provided as a file name without path
Dim Wkb As Workbook

On Error Resume Next
Set Wkb = Workbooks(stName)
If Not Wkb Is Nothing Then
IsWorkbookOpen = True
End If
End Function

thanks a lot
Aivars