Strange, code works on one computer but not another

J

Joel

TIA:

When I run code below on one computer works fine (cycles through all files
in the folder once)...another computer the code opens and cycles through all
files in the folder but opens the first file a second time and then stops.
If I delete the first file in the folder, all is OK, the code cycles through
all files once and stops. The files in the folder are created and exported
from Access.

Same versions of software (2003) and windows on both computers. How can
this be???

Thanks,

Joel

Sub OpnFilesNew()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\Copper") 'change directory
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name

'do stuff

Workbooks(objFile.Name).Save
Workbooks(objFile.Name).Close True 'saves changes
End If
Next
End Sub
 
J

JLGWhiz

TIA:

When I run code below on one computer works fine (cycles through all files
in the folder once)...another computer the code opens and cycles through all
files in the folder but opens the first file a second time and then stops.
If I delete the first file in the folder, all is OK, the code cycles through
all files once and stops. The files in the folder are created and exported
from Access.

Same versions of software (2003) and windows on both computers. How can
this be???

Thanks,

Joel

Sub OpnFilesNew()
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As Object


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder("c:\Copper") 'change directory
For Each objFile In objFolder.Files
If objFile.Type = "Microsoft Excel Worksheet" Then
Workbooks.Open Filename:=objFolder.Path & "\" & objFile.Name

'do stuff

Workbooks(objFile.Name).Save
Workbooks(objFile.Name).Close True 'saves changes
End If
Next
End Sub
 
J

Joel

Mr Whiz...

Windows Explorer only shows one file in the folder. I delete all of the
files, run Access to generate the files and the problem still exists. How
can there be more than one file with the same name in the folder anyway?

???

Thanks for any additional ideas.

Joel
 
J

JLGWhiz

You are correct that there should not be two files of the same name in a
folder, but it sounds like the program is opening a second instance of the
file rather than the same file twice. If that is in fact, what is happening,
then something on the maverick computer is causing your SQL to think it has
not finished the job. That is the type of thing you have to look for when
trouble shooting. I have seen files with the same name in the same folder,
with different extensions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top