|
-
Sep 14th, 2001, 08:03 AM
#1
Thread Starter
Hyperactive Member
Is there a faster way? (vb and Excel)
I have Created an app that can open up an excel template, let the user enter info and then I save the entered info to my SQL database. What I do for easy cell access I have defined a name for each cell the user can enter info into so i can track down where the info came from. here is my code to save the excel info into SQL.
VB Code:
Private Sub SaveInfo()
On Error GoTo Handler
Dim info() As String, test() As String
Dim strSummary As String
Dim i As Integer
Dim strPricing As String
'MouseIcon = vbHourglass
ReDim info(0)
With xls
Dim a As String, b As String, c As String
'--Set intial and max value for progress bar
pbExcel.Value = 0
pbExcel.Max = .Workbooks(1).Names.Count
'--loop thru all the Excel work book Names
'---This also includes some names that were probably pre-defined
For i = 1 To .Workbooks(1).Names.Count
Debug.Print i
'--This function Figures out which sheet the Name came from.
'--If the Name is not a name I defined the return value is "Stop"
a = GetSheet(.Workbooks(1).Names(i).Name)
Debug.Print .Workbooks(1).Names(i).Name
'--If the defined name leads with "S_" then add value to strSummary
If Left(.Workbooks(1).Names(i).Name, 2) = "S_" Then
'Debug.Assert .Workbooks(1).Names(i).Name <> "S_OtherHO"
strSummary = strSummary & .Sheets(a).Range(.Workbooks(1).Names(i).Name).Value & "@" & .Workbooks(1).Names(i).Name & ";"
Else
'--If Sheet doesn't equal Stop then it is a name I assigned to the cell
If a <> "Stop" Then
'--EX: 1.25 @ FLD_CELL
strPricing = .Sheets(a).Range(.Workbooks(1).Names(i).Name).Value & "@" & .Workbooks(1).Names(i).Name & ","
End If
End If
pbExcel.Value = i
Next i
End With
AddPricingInfo strPricing, strSummary
'Screen.MousePointer = 99
MsgBox "Saved Successfully", vbInformation
Exit Sub
Handler:
Select Case Err.Number
Case 13
Resume Next
Case Else
Err.Raise Err.Number, Err.Source, Err.Description
End Select
End Sub
The code is a bit ugly, but it works. The only problem is there are roughly 600 cells this thing has to go thru and it take about 15-20 seconds to do so. Can anyone come up with a faster way of doing this?
The reason I Concatinate all the cell values together is, so i can store the value in only one field in my database. The alternative would be to make 600 columns, not a very nice option. 
again, any suggestions on how to speed this up would be GREATLY appreciated.
Scott
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|