Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
MWS MWS is offline
external usenet poster
 
Posts: 53
Default Systematically Importing Data to Excel

Hello, I'm trying to attach code to a command button, which allows the users
to a) select one of several Microsoft Windows 2000 Notepad files and then b)
have the data from the file imported into excel.

The code is as follows:

Private Sub CommandButton1_Click()

'launches OPEN file process
Dim fName As Variant
Dim fName1 As String
fName = Application.GetOpenFilename

If fName = False Then
MsgBox "No File Selected - Data Import Aborted"
Exit Sub
End If
fName1 = Dir(fName)
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & fName, Destination:=Range("A1"))
.Name = Left(fName1, Len(fName1) - 4)

.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileFixedColumnWidths = Array(15, 10, 8, 33, 21, 31)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False

End With

End Sub

Upon execution, the code halts at the ".Refresh BackgroundQuery:=False" line
and the following error message is displayed:

Run-time error '-2147417848 (80010108)'
Automation error
The object invoked has disconnected from its clients

This is th efirst time I'm trying to automate this process and cannot
determine how to correct the problem. How can I coorect this situation? If a
more streamlined or less problematic approach exists, please share.

Any and All Help Is Appreciated - Thank You



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Systematically updating references to other workbooks Flipper Excel Discussion (Misc queries) 9 August 27th 09 09:22 PM
How do I systematically do this? JayPee Excel Discussion (Misc queries) 3 August 14th 08 07:33 PM
Importing data into Excel mwy Excel Discussion (Misc queries) 0 June 12th 08 09:17 PM
Data types when importing Excel data to SQLServer [email protected] Excel Discussion (Misc queries) 1 September 27th 06 12:48 PM
Importing Excel data Grace[_3_] Excel Programming 1 February 26th 04 03:39 PM


All times are GMT +1. The time now is 01:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"