Nitin Shah
asked on
vb6, excel Run-time error 1004 method 'close' of object 'workbooks' failed
I have following code in VB6 application where i open file for reading and storing values in dimension. i close the file and open file again for updating values. but while closing it give error Run-time error 1004 Method 'Close' of object 'Workbooks' failed'
following is my code
Dim XLSBK As New Excel.Application
Dim XLwsh As New Excel.Worksheet
Dim fs
Set fs = CreateObject("scripting.fi lesystemob ject")
SelParamFileName = Trim(ctlSELPARAMFILENAME.T ext)
If Trim(Len(SelParamFileName) ) = 0 Then
MsgBox "Select Excel Parameter file", vbCritical, Me.Caption
' cmdPARAMSEARCH.SetFocus
Exit Sub
End If
'************************* ********** ********** ********** ********** *****
If Not fs.FileExists(SelParamFile Name) Then
MsgBox "Warning - Not a valid Excel Parameter file name ", vbCritical
Exit Sub
End If
'************************* ********** ********** ********** ********** *****
XLSBK.DefaultFilePath = SelParamFileName
'************************* ********** ********** ********** ********** *****
XLSBK.Workbooks.Open SelParamFileName, , , , , , , , , True
XLSBK.Visible = False
For Ctr = 1 to 20
XLSBK.Cells(Ctr, 11) = "updateremark"
next
XLSBK.Workbooks.Close ( ON THIS LINE SYSTEM GOT HANG AND GIVE MESSAGE RETRY OR SWITCH TO - WHEN PRESS CLT+ALT+DEL
TO TERMINATE PROCESS - ERROR 1004 )
Thanks in advance .
following is my code
Dim XLSBK As New Excel.Application
Dim XLwsh As New Excel.Worksheet
Dim fs
Set fs = CreateObject("scripting.fi
SelParamFileName = Trim(ctlSELPARAMFILENAME.T
If Trim(Len(SelParamFileName)
MsgBox "Select Excel Parameter file", vbCritical, Me.Caption
' cmdPARAMSEARCH.SetFocus
Exit Sub
End If
'*************************
If Not fs.FileExists(SelParamFile
MsgBox "Warning - Not a valid Excel Parameter file name ", vbCritical
Exit Sub
End If
'*************************
XLSBK.DefaultFilePath = SelParamFileName
'*************************
XLSBK.Workbooks.Open SelParamFileName, , , , , , , , , True
XLSBK.Visible = False
For Ctr = 1 to 20
XLSBK.Cells(Ctr, 11) = "updateremark"
next
XLSBK.Workbooks.Close ( ON THIS LINE SYSTEM GOT HANG AND GIVE MESSAGE RETRY OR SWITCH TO - WHEN PRESS CLT+ALT+DEL
TO TERMINATE PROCESS - ERROR 1004 )
Thanks in advance .
XLSBK.Workbooks(SelParamFi leName).Cl ose
ASKER
Dear Martin Liss
XLSBK.Workbooks(SelParamFi leName).Cl ose
is giving error - Subscript out range
XLSBK.Workbooks(SelParamFi
is giving error - Subscript out range
Try
XLSBK.Workbooks(1).Close
XLSBK.Workbooks(1).Close
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear Ryan Chong
It is working file but at instruction
XLSworkbook.Save - It give message ' A file namned 'RESUME.XLW' already exists in this location. do want to replace it?
yes - no - cancel
when i say YES it is saving in same file. but i could not find file name in my computer - 'RESUME.XLW'
thanks sir
It is working file but at instruction
XLSworkbook.Save - It give message ' A file namned 'RESUME.XLW' already exists in this location. do want to replace it?
yes - no - cancel
when i say YES it is saving in same file. but i could not find file name in my computer - 'RESUME.XLW'
thanks sir
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ryan Chong,
It is working fine.
Thanks for kind prompt reply.
Thanks
It is working fine.
Thanks for kind prompt reply.
Thanks