ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Unable to read file (https://www.excelbanter.com/excel-programming/399445-unable-read-file.html)

MarkS

Unable to read file
 
Hi,
In VBA I have this line
Workbooks.Open sAFMAPathName & sFileName

when in auto it gives a error message 'Unable to read file' when I single
step (F8), it works fine.
This section of the code comes from another excel VBA code block which works
fine, if a bit slow.

Thanks

Tim Williams

Unable to read file
 
If it works fine when stepping through then most likely there is some delay
in creating or releasing the file you're trying to open.
Where does it come from ?

Tim

"MarkS" wrote in message
...
Hi,
In VBA I have this line
Workbooks.Open sAFMAPathName & sFileName

when in auto it gives a error message 'Unable to read file' when I single
step (F8), it works fine.
This section of the code comes from another excel VBA code block which
works
fine, if a bit slow.

Thanks




MarkS

Unable to read file
 
Hi Tim,
from a remote server, but some work fine and others don't

MarkS

"Tim Williams" wrote:

If it works fine when stepping through then most likely there is some delay
in creating or releasing the file you're trying to open.
Where does it come from ?

Tim

"MarkS" wrote in message
...
Hi,
In VBA I have this line
Workbooks.Open sAFMAPathName & sFileName

when in auto it gives a error message 'Unable to read file' when I single
step (F8), it works fine.
This section of the code comes from another excel VBA code block which
works
fine, if a bit slow.

Thanks





Tim Williams

Unable to read file
 
Do the files which give problems fail consistently ?

Tim


"MarkS" wrote in message
...
Hi Tim,
from a remote server, but some work fine and others don't

MarkS

"Tim Williams" wrote:

If it works fine when stepping through then most likely there is some
delay
in creating or releasing the file you're trying to open.
Where does it come from ?

Tim

"MarkS" wrote in message
...
Hi,
In VBA I have this line
Workbooks.Open sAFMAPathName & sFileName

when in auto it gives a error message 'Unable to read file' when I
single
step (F8), it works fine.
This section of the code comes from another excel VBA code block which
works
fine, if a bit slow.

Thanks







MarkS

Unable to read file
 
Yes Its always the same ones but opening them and resaving them doesn't help

"Tim Williams" wrote:

Do the files which give problems fail consistently ?

Tim


"MarkS" wrote in message
...
Hi Tim,
from a remote server, but some work fine and others don't

MarkS

"Tim Williams" wrote:

If it works fine when stepping through then most likely there is some
delay
in creating or releasing the file you're trying to open.
Where does it come from ?

Tim

"MarkS" wrote in message
...
Hi,
In VBA I have this line
Workbooks.Open sAFMAPathName & sFileName

when in auto it gives a error message 'Unable to read file' when I
single
step (F8), it works fine.
This section of the code comes from another excel VBA code block which
works
fine, if a bit slow.

Thanks







MarkS

Unable to read file
 
No thats no right, The first one always loads fine and the next one has the
problem

"MarkS" wrote:

Yes Its always the same ones but opening them and resaving them doesn't help

"Tim Williams" wrote:

Do the files which give problems fail consistently ?

Tim


"MarkS" wrote in message
...
Hi Tim,
from a remote server, but some work fine and others don't

MarkS

"Tim Williams" wrote:

If it works fine when stepping through then most likely there is some
delay
in creating or releasing the file you're trying to open.
Where does it come from ?

Tim

"MarkS" wrote in message
...
Hi,
In VBA I have this line
Workbooks.Open sAFMAPathName & sFileName

when in auto it gives a error message 'Unable to read file' when I
single
step (F8), it works fine.
This section of the code comes from another excel VBA code block which
works
fine, if a bit slow.

Thanks







Tim Williams

Unable to read file
 
Without seeing the code it's hard to say exactly what the problem might be.
Try putting a small delay before opening each file and see if that fixes it.

Tim.


"MarkS" wrote in message
...
No thats no right, The first one always loads fine and the next one has
the
problem

"MarkS" wrote:

Yes Its always the same ones but opening them and resaving them doesn't
help

"Tim Williams" wrote:

Do the files which give problems fail consistently ?

Tim


"MarkS" wrote in message
...
Hi Tim,
from a remote server, but some work fine and others don't

MarkS

"Tim Williams" wrote:

If it works fine when stepping through then most likely there is
some
delay
in creating or releasing the file you're trying to open.
Where does it come from ?

Tim

"MarkS" wrote in message
...
Hi,
In VBA I have this line
Workbooks.Open sAFMAPathName & sFileName

when in auto it gives a error message 'Unable to read file' when I
single
step (F8), it works fine.
This section of the code comes from another excel VBA code block
which
works
fine, if a bit slow.

Thanks









MarkS

Unable to read file
 
Hi Tim,
Have tried a 10 second delay no improvement

Do While iFilesUsedCounter < 9
' Open AFMA WorkBook
sFileName = AFMAFiles(iFileCounter).sFileName
Debug.Print sAFMAPathName & sFileName
Workbooks.Open sAFMAPathName & sFileName
Cells.Select
Selection.Copy
ThisWorkbook.Activate
Sheets("AFMA Loader").Select
Cells.Select
ActiveSheet.Paste
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Windows(sFileName).Activate
Application.CutCopyMode = False 'Clear Clipboard
ActiveWindow.Close saveChanges:=False

some other stuff to put it in the right place do it again until we have a
complete set


"Tim Williams" wrote:

Without seeing the code it's hard to say exactly what the problem might be.
Try putting a small delay before opening each file and see if that fixes it.

Tim.



Tim Williams

Unable to read file
 
If you comment out all the copy/paste stuff can you just open and close the
files in a loop ?
Might help to simplify the situation for debugging.

You do have two different counters, right? iFilesUsedCounter and
iFileCounter ?


Tim



"MarkS" wrote in message
...
Hi Tim,
Have tried a 10 second delay no improvement

Do While iFilesUsedCounter < 9
' Open AFMA WorkBook
sFileName = AFMAFiles(iFileCounter).sFileName
Debug.Print sAFMAPathName & sFileName
Workbooks.Open sAFMAPathName & sFileName
Cells.Select
Selection.Copy
ThisWorkbook.Activate
Sheets("AFMA Loader").Select
Cells.Select
ActiveSheet.Paste
Selection.Copy
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=
_
False, Transpose:=False
Windows(sFileName).Activate
Application.CutCopyMode = False 'Clear Clipboard
ActiveWindow.Close saveChanges:=False

some other stuff to put it in the right place do it again until we have a
complete set


"Tim Williams" wrote:

Without seeing the code it's hard to say exactly what the problem might
be.
Try putting a small delay before opening each file and see if that fixes
it.

Tim.






All times are GMT +1. The time now is 12:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com