Advertisement
Advertisement
| 09.05.2008 at 01:37PM PDT, ID: 23707642 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: |
Option Explicit
Sub testload()
Dim strFilePath As String, strFilename As String, strFullPath As String
Dim xlbook As Workbook
Dim lngCounter As Long
Dim oConn As Object, oRS As Object, oFSObj As Object
Dim sheetcount As Integer
'Get a text file name
strFullPath = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Please selec text file...")
If strFullPath = "False" Then Exit Sub 'User pressed Cancel on the open file dialog
'This gives us a full path name e.g. C:tempfolderfile.txt
'We need to split this into path and file name
Set oFSObj = CreateObject("SCRIPTING.FILESYSTEMOBJECT")
strFilePath = oFSObj.GetFile(strFullPath).ParentFolder.Path
strFilename = oFSObj.GetFile(strFullPath).Name
Set xlbook = Application.Workbooks.Add
For sheetcount = xlbook.Sheets.Count To 1 Step -1
Application.DisplayAlerts = False
If sheetcount > 1 Then xlbook.Sheets(sheetcount).Delete
Application.DisplayAlerts = True
Next
'Open an ADO connection to the folder specified
Set oConn = CreateObject("ADODB.CONNECTION")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strFilePath & ";" & _
"Extended Properties=""text;HDR=No;FMT=Delimited"""
Set oRS = CreateObject("ADODB.RECORDSET")
'Now actually open the text file and import into Excel
oRS.Open "SELECT * FROM " & strFilename, oConn, 3, 1, 1
While Not oRS.EOF
xlbook.Sheets.Add after:=Sheets(xlbook.Sheets.Count)
xlbook.ActiveSheet.Range("A1").CopyFromRecordset oRS, 65536
Wend
Application.DisplayAlerts = False
xlbook.Sheets(1).Delete
Application.DisplayAlerts = True
For sheetcount = 1 To xlbook.Sheets.Count
xlbook.Sheets(sheetcount).Name = "Sheet" & sheetcount
Next
oRS.Close
oConn.Close
ThisWorkbook.Close
End Sub
|