VB to search Excell Sheets
From: wssparky (ws_at_sparky.com)
Date: 02/21/04
- Next message: Mike D Sutton: "Re: Calling unmanaged dll from Vb.NET"
- Previous message: wssparky: "Re: How start with XLS files Vb6"
- Next in thread: Jim Edgar: "Re: VB to search Excell Sheets"
- Reply: Jim Edgar: "Re: VB to search Excell Sheets"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 21 Feb 2004 09:05:45 -0800
Hi,
I need some help.
The following code is part of a Time Clock program.
The employees will enter the last 4 numbers of the SSN (Readout)
and the program will open the Excel Book “TimeSheet.xls”
and match it up to the number in cell “E5”.
Each sheet in the book is named as the last 4 numbers of the SSN.
It will then print the date and time in the Excel sheet as well as
display
the employees name “B2”, number ”E5”, and time clocked in or out
on the VB display (Readout2).
The problem is I cant get it to loop through the sheets and find the SSN
.
This is just my approach to the program,
( learned from Devdex.com – Thanks for your Help !!) if you see a better
way
of doing anything else, PLEASE let me know. I need this to run as fast
as possible
and be easy to run as well.
One more thing, I’m just learning VB6 so please go slow.
Thanks for any help in advance
Option Explicit
Dim m_XLApp As Excel.Application
Dim m_XLWorkbook As Excel.Workbook
Private Sub Enter_Click()
Dim FileNamePath As String
Dim FileName As String
Dim S1 As Excel.Worksheet
Dim EmpNumber As String
Dim EmpName As String
Dim EName As String
Dim SheetName As String
FileName = "TimeSheet.xls"
FileNamePath = "C:\TestTime\TimeSheet.xls"
'Clear any info in boxes
EmpNumber = ""
EmpName = ""
Set m_XLApp = Excel.Application
m_XLApp.Visible = True
Set m_XLWorkbook = m_XLApp.Workbooks.Open(FileNamePath)
m_XLWorkbook.RunAutoMacros Which:=xlAutoOpen
For Each S1 In m_XLWorkbook.Worksheets()
EmpNumber = S1.Range("E4")
EmpName = S1.Range("B2")
If EmpNumber = Readout Then EName = EmpName
' New Employee
If Readout = "9" Then Module1.NewEmp
If Readout = "9" Then Readout2 = ""
If Readout = "9" Then Readout = ""
If Readout = "" Then Exit Sub
'If Error
If EmpName = "" Then Module1.NoFile
If EmpName = "" Then Readout = ""
If EmpName = "" Then Exit Sub
Next S1
SheetName = Readout
m_XLWorkbook.Worksheets(SheetName).Range("A10") = Format(Now, "Short
Date")
m_XLWorkbook.Worksheets(SheetName).Range("F11") = Label1.Caption
Readout2 = Format("Employee Name : " + EmpName) & vbCrLf & _
Format("Employee Number : " + Readout) & vbCrLf & _
Format("Time : " + Label1.Caption)
Readout = ""
m_XLWorkbook.Save
m_XLWorkbook.Close True
End Sub
wssparky______________________
We learn by doing, and doing ……and doing ……
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
- Next message: Mike D Sutton: "Re: Calling unmanaged dll from Vb.NET"
- Previous message: wssparky: "Re: How start with XLS files Vb6"
- Next in thread: Jim Edgar: "Re: VB to search Excell Sheets"
- Reply: Jim Edgar: "Re: VB to search Excell Sheets"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|