ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Open a specific file (https://www.excelbanter.com/excel-programming/322743-open-specific-file.html)

anomymousA

Open a specific file
 
Hi,

First of all, I aplogize for the bad quality of my english but I already
asked this question on the French Newsgroup and got no answers.

I encounter a difficulty in Excel to open a given file.

Let's be more specific. In a given repertory, I have 2 files which have the
same name but one is without extension and the other with a extension.xls.
The 1st one is text but is imported from another application (not OFFICE).
By the following procedure, I let the user chose the file he wishes. The
difficulty is that when he clicks on the file without extension, Excel is
obstinated to open the Excel file by defect.
Carry out the test by creating a textual file toto.txt and remove its
extension in the Explorer then create a file toto.xls in the same repertory.
You use the following procedure and you will see that Excel always opens
toto.xls even if you have chosed the one without extension, or then it is
that there is another thing and it is precisely what I'm looking for. I use
Excel 2000 and win NT4.

Set fso = CreateObject("Scripting.FileSystemObject")

ctrl1 = False

While ctrl1 = False
Set filetopen = Nothing
filetoopen = Application.GetOpenFilename
If filetoopen < False Then
If (fso.GetFile(filetoopen).Type < "File" And
fso.GetFile(filetoopen).Type < "Document texte") Then
MsgBox "You didn't choose a Text file or a file with non extension"
& Chr(13) & "Abort or retry"
Else
ctrl1 = True
End If
Else
Set fso = Nothing
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.AskToUpdateLinks = True
.EnableCancelKey = xlInterrupt
End With
Exit Sub
End If
Wend

Workbooks.OpenText Filename:=filetoopen, Origin:=xlWindows, Tab:=True,
Other:=True, OtherChar:="!"

In addition, if the file don't have any extension, Windows, at the time of
the assignment of filetoopen , sticks a point at its end .
Sure I could ask the users to carry an extension to the files which they
extract from the other application, which would solve the problem but I want
to understand if it is possible to make Excel open the file which I wish and
not another one.

Thanks

A+


Tom Ogilvy

Open a specific file
 
http://support.microsoft.com/default...b;en-us;157320
XL97: Macro Cannot Open a File That Has No Extension


http://support.microsoft.com/default...b;en-us;213785
XL2000: Macro Cannot Open a File That Has No Extension

Looks like it hasn't been fixed.

--
Regards,
Tom Ogilvy

"anomymousA" wrote in message
...
Hi,

First of all, I aplogize for the bad quality of my english but I already
asked this question on the French Newsgroup and got no answers.

I encounter a difficulty in Excel to open a given file.

Let's be more specific. In a given repertory, I have 2 files which have

the
same name but one is without extension and the other with a extension.xls.
The 1st one is text but is imported from another application (not

OFFICE).
By the following procedure, I let the user chose the file he wishes. The
difficulty is that when he clicks on the file without extension, Excel is
obstinated to open the Excel file by defect.
Carry out the test by creating a textual file toto.txt and remove its
extension in the Explorer then create a file toto.xls in the same

repertory.
You use the following procedure and you will see that Excel always opens
toto.xls even if you have chosed the one without extension, or then it is
that there is another thing and it is precisely what I'm looking for. I

use
Excel 2000 and win NT4.

Set fso = CreateObject("Scripting.FileSystemObject")

ctrl1 = False

While ctrl1 = False
Set filetopen = Nothing
filetoopen = Application.GetOpenFilename
If filetoopen < False Then
If (fso.GetFile(filetoopen).Type < "File" And
fso.GetFile(filetoopen).Type < "Document texte") Then
MsgBox "You didn't choose a Text file or a file with non

extension"
& Chr(13) & "Abort or retry"
Else
ctrl1 = True
End If
Else
Set fso = Nothing
With Application
.DisplayAlerts = True
.ScreenUpdating = True
.AskToUpdateLinks = True
.EnableCancelKey = xlInterrupt
End With
Exit Sub
End If
Wend

Workbooks.OpenText Filename:=filetoopen, Origin:=xlWindows, Tab:=True,
Other:=True, OtherChar:="!"

In addition, if the file don't have any extension, Windows, at the time of
the assignment of filetoopen , sticks a point at its end .
Sure I could ask the users to carry an extension to the files which they
extract from the other application, which would solve the problem but I

want
to understand if it is possible to make Excel open the file which I wish

and
not another one.

Thanks

A+




anonymousA

Open a specific file
 
Great Thanks to you, Tom

reading you once more, I can confirm you're one of the bests.

So long


Tom Ogilvy a écrit :
http://support.microsoft.com/default...b;en-us;157320
XL97: Macro Cannot Open a File That Has No Extension


http://support.microsoft.com/default...b;en-us;213785
XL2000: Macro Cannot Open a File That Has No Extension

Looks like it hasn't been fixed.



All times are GMT +1. The time now is 02:03 PM.

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