file close problem

  • Thread starter Thread starter David Holland
  • Start date Start date
D

David Holland

Hi

I am opening another XLS file, copying some data from that file, but when I
go to close it, I can't. I think it is just looking for the Workbook Name to
close it
Problem is that I don't know how to find the workgroup name. Belwo is some
of waht I am using

fileToOpen = Application.GetOpenFilename("XLS Files (*.xls), *.xls")
If fileToOpen = False Then
yesno = MsgBox("The file is invalid ... Do you want to try
again ?", vbYesNo + vbCritical, "Caution")
Select Case yesno
Case vbYes
GoTo cont
Case vbNo
GoTo theend
End Select

Do some stuff with the file

Windows(fileToOpen).Activate
ActiveWindow.Close

The above two lines is the real problem

Thanks for reading & even more thanks if you can help.

Regards David
 
David,

I don't see where you opened the file.

Workbooks.Open fileToOpen
FileName = ActiveWorkbook.Name ' get name

'Do some stuff with the file

Windows(FileName).Activate
Workbooks(FileName).Close
 
Does this help.

fileToOpen = Application _
.GetOpenFilename("XLS Files (*.xls), *.xls")
If fileToOpen = False Then
yesno = MsgBox("The file is invalid ... Do you want to try again ?",
vbYesNo + vbCritical, "Caution")
Select Case yesno
Case vbYes
GoTo cont
Case vbNo
GoTo theend
End Select

End If


Regards David
 
Instead of going through the windows collection, it might be better to use a
workbook variable that represents your newly opened workbook:

dim fileToOpen as variant
dim wkbk as workbook

cont: 'here???
fileToOpen = Application _
.GetOpenFilename("XLS Files (*.xls), *.xls")
If fileToOpen = False Then
yesno = MsgBox("The file is invalid ... Do you want to try again ?", _
vbYesNo + vbCritical, "Caution")
Select Case yesno
Case vbYes
GoTo cont
Case vbNo
GoTo theend
End Select
End If

set wkbk = workbooks.open(filename:=filetoopen)
'do lots of things

wkbk.close savechanges:=False 'True '????
 
Back
Top