G
gerico.one
I save an excel file with a VB 6 application,but
if in excel the same name file is already open...a bad problem !!!
i need a control. (if the il file is open or closed..)
thanks,bye
Private Sub Command1_Click()
Dim MyEx As Object
Dim Myws As Object
Dim Myrange As Object
Dim FileName As New Scripting.FileSystemObject
Dim name As String
On Error GoTo hell
Set MyEx = CreateObject("Excel.Application")
Set Myws = MyEx.Workbooks.Add.Worksheets.Item(1)
Set Myrange = Myws.Range("A1", "C1")
Myrange.Font.Bold = True
Set Myrange = Myws.Range("A1")
Myrange.Offset(0, 0).Value = "COL1"
Myrange.Offset(0, 1).Value = "COL2"
Myrange.Offset(0, 2).Value = "COL3"
Myrange.Offset(1, 1).Value = "Ciccio1"
Myrange.Offset(2, 2).Value = "Ciccio2"
name = "C:\Ciccio.xls"
'********************************
If FileName.FileExists(name) = True Then
Myws.SaveWorkspace name
Else
MsgBox ("this file name is already used.")
End If
'*********************************
MyEx.Quit
Set Myrange = Nothing
Set Myws = Nothing
Set MyEx = Nothing
Exit Sub
hell:
MsgBox ("hell!!!!!!!!!!!")
MsgBox Err.Number & ", " & Err.Description & ", " & Err.HelpContext
End Sub
if in excel the same name file is already open...a bad problem !!!
i need a control. (if the il file is open or closed..)
thanks,bye
Private Sub Command1_Click()
Dim MyEx As Object
Dim Myws As Object
Dim Myrange As Object
Dim FileName As New Scripting.FileSystemObject
Dim name As String
On Error GoTo hell
Set MyEx = CreateObject("Excel.Application")
Set Myws = MyEx.Workbooks.Add.Worksheets.Item(1)
Set Myrange = Myws.Range("A1", "C1")
Myrange.Font.Bold = True
Set Myrange = Myws.Range("A1")
Myrange.Offset(0, 0).Value = "COL1"
Myrange.Offset(0, 1).Value = "COL2"
Myrange.Offset(0, 2).Value = "COL3"
Myrange.Offset(1, 1).Value = "Ciccio1"
Myrange.Offset(2, 2).Value = "Ciccio2"
name = "C:\Ciccio.xls"
'********************************
If FileName.FileExists(name) = True Then
Myws.SaveWorkspace name
Else
MsgBox ("this file name is already used.")
End If
'*********************************
MyEx.Quit
Set Myrange = Nothing
Set Myws = Nothing
Set MyEx = Nothing
Exit Sub
hell:
MsgBox ("hell!!!!!!!!!!!")
MsgBox Err.Number & ", " & Err.Description & ", " & Err.HelpContext
End Sub