Thread: with files
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default with files

Mark,
It seems that function Excel function does not support using wildcards in
the extension. If you cannot get it to work, the API route will work.

NickHK

"Mark" wrote in message
...
Your code not pass ..
in:Filenames = Application.GetOpenFilename("test files
(test.*),test.*", , , True)
occur run-time error 1004:
Method 'GetOpenFilename' of object ' _Application' failed.
info:
I've files test.* in the same folder.
What doing GetOpenFilename?
i've excel and win 2k.
Regards
Mark

-----Original Message-----
Hi,
Something like the code below should do it:

Sub Read_Line5_Line6()
Dim Filenames, Filenumber As Integer
Dim LineCounter As Integer, Data, Line5In(), Line6In()
Dim outRng As Range, i As Long

Filenames = Application.GetOpenFilename("test files
(test.*),test.*", , , True)
If Not IsArray(Filenames) Then MsgBox "No files
selected.", vbInformation: Exit Sub
ReDim Line5In(1 To 1)
ReDim Line6In(1 To 1)
'Read files and put lines 5 and 6 into vectors
For i = LBound(Filenames) To UBound(Filenames)
Filenumber = FreeFile
LineCounter = 0
Open Filenames(i) For Input As #Filenumber
Do While Not EOF
Line Input #Filenumber, Data
LineCounter = LineCounter + 1
If LineCounter = 5 Then
Line5In(UBound(Line5In)) = Data
ReDim Preserve Line5In(1 To UBound(Line5In) +
1)
ElseIf LineCounter = 6 Then
Line6In(UBound(Line6In)) = Data
ReDim Preserve Line6In(1 To UBound(Line6In) +
1)
Close #Filenumber
Exit Do
End If
Loop
Next
ReDim Preserve Line5In(1 To UBound(Line5In) - 1)
ReDim Preserve Line6In(1 To UBound(Line6In) - 1)
' Define workbook where data are to be located
Workbooks("SomeName").Activate
' Define worksheet where data are to be located
Worksheets("Somename").Activate
Set outRng = Range(Cells(1, 1), Cells(UBound(Line5In), 1))
outRng.Value = Application.WorksheetFunction.Transpose
(Line5In)
Set outRng = Range(Cells(1, 1), Cells(UBound(Line6In), 1))
outRng.Value = Application.WorksheetFunction.Transpose
(Line6In)

End Sub

-----Original Message-----
Hi,
I have in folder with different files. I'd like, in all
files with name "test" and different extension
e.g. "test.102", "test.aaa", "test.108", "test.120" ,

get
line 5 and 6 and put in worksheet in two columns(for

first
file A1 (line 5) and B1 (line 6) for following file A2

and
B2 etc.
Is there any smart solution?

Regards
Mark
.

.