Peter Chan
asked on
Problem to open text file
Hi,
I get
due to last line below
c:\cmp\0002ASC_COSCO FORTUNE_032E_E_SD_STACO_00 02.06187.a sc
as file name to the prompt to open this file.
https://1drv.ms/u/s!Ai8CrEskdewXky2ITSgFsh6EUct9
I get
due to last line below
Repeat1:
File0 = InputBox("Enter Text file name to check any comparison:", "Text file")
If InStr(File0, ".") > 0 Then
'File1 = Mid(File0, 1, InStr(File0, ".") - 1)
File1 = File0
Else
File1 = File0 & ".asc"
End If
'If Dir(File1 & ".xls") = "" And Dir(File1 & ".xlsm") = "" And Dir(File1 & ".xlsx") = "" Then
If Dir(File1) = "" Then
MsgBox "Invalid Text file name is entered!"
GoTo Repeat1
End If
Worksheets(Sheet0).Columns(38).ClearContents
Set Range0 = Worksheets(Sheet0).Range("BL2:BL2")
Range0.Font.Size = 10
Range0.Font.Bold = True
Range0.Font.Color = RGB(192, 80, 77)
RowID = 1: Count0 = 0
Open File1 For Input As #iFile
after I've putc:\cmp\0002ASC_COSCO FORTUNE_032E_E_SD_STACO_00
as file name to the prompt to open this file.
https://1drv.ms/u/s!Ai8CrEskdewXky2ITSgFsh6EUct9
or try like this:
...
Dim iFile As Integer
iFile = FreeFile
RowID = 1: Count0 = 0
Open File1 For Input As #iFile
...
Maybe you should enclose the filename with "-s, because the filename contains a space, probably Excel tries to open 'c:\cmp\0002ASC_COSCO' as file which fails.
Your first part should be
Do Until File1 <> ""
File0 = InputBox("Enter Text file name to check any comparison:", "Text file")
If InStr(File0, ".") > 0 Then
File1 = File0
Else
File1 = File0 & ".asc"
End If
If File1 = "" Then
MsgBox "Invalid Text file name is entered!"
End If
Loop
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Note: this is an Integer data type.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@HuaMinChen,
I think it would be most helpful if you described what you are trying to accomplish with the code. A number of experts are 'guessing' at your intention, but it would help to have more info from you.
Is the file you want to "open" going to be an Excel workbook file, or a text file?
Do you want to actually open it in Excel, or just open it as a text file for reading?
It's not clear what you want to happen after you have "access" to the file, so it's hard to advise you on the best code to use.
~bp
I think it would be most helpful if you described what you are trying to accomplish with the code. A number of experts are 'guessing' at your intention, but it would help to have more info from you.
Is the file you want to "open" going to be an Excel workbook file, or a text file?
Do you want to actually open it in Excel, or just open it as a text file for reading?
It's not clear what you want to happen after you have "access" to the file, so it's hard to advise you on the best code to use.
~bp
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
quick solution would be:
Open in new window