Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 32
Default Recurrent error: disconnection from clients

I sometimes get the error "The object invoked has disconnected from its
clients" when my macro tries to import TXT files. There seem to be many
different causes of this error posted in the forum. Any suggestions about
what is going wrong in my case?

Hint: if I actually import a file manually, then run the macro (without
changing the CurDir, although I don't know if it matters), I do not get the
error. If I close all open workbooks, the error comes back, even though the
macro creates a new workbook before attempting the import.

The relevant code is:

Workbooks.Add
iReport = 0
vFile = Dir("*.TXT")
If vFile = "" Then
Call MsgBox("No TXT files found in folder " & CurDir, vbExclamation, _
"Grab_Reports()")
Exit Sub
End If

While vFile < ""
iReport = iReport + 1
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & vFile, _
Destination:=Range("A1"))
.Name = "Report" & str(iReport)
.FieldNames = True
.RowNumbers = False ' might want 'True' for
Access export
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = nHeaderRows + 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 1, 1,
1, 1)
.TextFileFixedColumnWidths = Array(5, 4, 17, 21, 4, 4, 24, 16, 8, 8,
4, 7, 7)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

vFile = Dir ' Next report ...
Sheets.Add
Wend

Thanks for any ideas!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Recurrent error: disconnection from clients

Hi
You could sprinkle your code with a few DoEvents (read the help on
issues with it). e.g at the end of each loop. It just means that one
loop is fully processed before the next kicks in....I think.
regards
Paul

Allen_N wrote:

I sometimes get the error "The object invoked has disconnected from its
clients" when my macro tries to import TXT files. There seem to be many
different causes of this error posted in the forum. Any suggestions about
what is going wrong in my case?

Hint: if I actually import a file manually, then run the macro (without
changing the CurDir, although I don't know if it matters), I do not get the
error. If I close all open workbooks, the error comes back, even though the
macro creates a new workbook before attempting the import.

The relevant code is:

Workbooks.Add
iReport = 0
vFile = Dir("*.TXT")
If vFile = "" Then
Call MsgBox("No TXT files found in folder " & CurDir, vbExclamation, _
"Grab_Reports()")
Exit Sub
End If

While vFile < ""
iReport = iReport + 1
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & vFile, _
Destination:=Range("A1"))
.Name = "Report" & str(iReport)
.FieldNames = True
.RowNumbers = False ' might want 'True' for
Access export
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = nHeaderRows + 1
.TextFileParseType = xlFixedWidth
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 4, 2, 1, 1,
1, 1)
.TextFileFixedColumnWidths = Array(5, 4, 17, 21, 4, 4, 24, 16, 8, 8,
4, 7, 7)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

vFile = Dir ' Next report ...
Sheets.Add
Wend

Thanks for any ideas!


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
How to stop a recurrent circular reference error message ? DaveWB3DWE Excel Discussion (Misc queries) 1 August 10th 07 05:10 PM
Automation Error: Object Disconnected From Clients Sprinks Excel Programming 1 October 24th 06 08:30 PM
Error using SaveAs (object disconnected from clients!) then XL Cra Philip Excel Programming 1 May 12th 05 12:05 AM
Automation Error: The Object Invoked Has Disconnected from Its Clients Vaibhav Dandavate Excel Programming 0 September 8th 03 04:05 PM


All times are GMT +1. The time now is 11:32 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"