Hello all,
I am new at VB6, but the more i learn, the more i love it! But i do have a question. I've created a form, the user has to choose an excel file from a list that they want to open, when they highlight the file name, the directory path shows up in another label box; then the user clicks the Open button to actually open the excel file for viewing. But what if the file doesn't exist yet? How do i add to my IF/Then statement a controlled message that tells the user that the file doesn't exist and to go back and select another file? Here is the code that i have so far:
Thanks,
Terra
I am new at VB6, but the more i learn, the more i love it! But i do have a question. I've created a form, the user has to choose an excel file from a list that they want to open, when they highlight the file name, the directory path shows up in another label box; then the user clicks the Open button to actually open the excel file for viewing. But what if the file doesn't exist yet? How do i add to my IF/Then statement a controlled message that tells the user that the file doesn't exist and to go back and select another file? Here is the code that i have so far:
Code:
Private Sub Command1_Click()
Dim xl
Dim xlsheet
Dim xlwbook
Dim MyFileName As String
Me.Label3.ShowWhatsThis
MyFileName = Me.Label3.Caption
If Me.Label3.Caption <> "" Or Me.Label3.Caption <> ".xls" Then
Set xl = CreateObject("Excel.Application")
Set xlwbook = xl.Workbooks.Open(MyFileName)
Set xlsheet = xlwbook.Sheets.Item(1)
xl.Visible = True
End If
End Sub
Private Sub Command2_Click()
Unload Form3
End Sub
Private Sub Form_Load()
List1.AddItem " BIO Only"
List1.AddItem " CHEM Only"
List1.AddItem " NUC Only"
List1.AddItem " ROTA Only"
End Sub
Private Sub List1_Click()
Label3.Caption = List1.Text
Select Case List1.ListIndex
Case 0
Label3.Caption = "C:\file1.xls"
Case 1
Label3.Caption = "C:\file2.xls"
Case 2
Label3.Caption = "C:\file3.xls"
Case 3
Label3.Caption = "C:\file4.xls"
End Select
End Sub
Terra
Comment