G
Guest
Hi, every month i have to import a file (with no extension, the name this
month is "SCNT200703") in a specific location ("C:\Files\").
Is it possible to use : "FileName = Application.GetOpenFilename("All files,
*.*")" but instead of ("All files, *.*") to put in there the exact location
and name of the file?
What i have so far is this:
Path = "C:\Files\"
FicheiroTratar = "SCNT" & Year(Now()) & Month(Now())
Set FicheiroActual = Workbooks.Add
FullName = Path & FicheiroTratar
FileName = Application.GetOpenFilename("All files, *.*")
For I = Len(FileName) To 1 Step -1
If Mid(FileName, I, 1) = "\" Then
FileName = Right(FileName, Len(FileName) - I)
Exit For
End If
Next
Debug.Print FileName
NomeFicheiroOrigem = Left(FileName, 10)
If FileName = "False" Then Exit Sub
x = 1
Open FileName For Input As #1
Do While Not EOF(1)
FicheiroActual.Activate
Input #1, Line$
ColunaA$ = Mid$(Line$, 1, 1)
ColunaB$ = Mid$(Line$, 2, 14)
ColunaC$ = Mid$(Line$, 15, 17)
ColunaD$ = Mid$(Line$, 32, 17)
Worksheets("Sheet1").Cells(x, 1).Value = ColunaA$
Worksheets("sheet1").Columns(2).NumberFormat = "@"
Worksheets("sheet1").Cells(x, 2).Value = ColunaB$
Worksheets("sheet1").Columns(2).NumberFormat = "@"
Worksheets("sheet1").Cells(x, 3).Value = ColunaC$
Worksheets("sheet1").Cells(x, 4).Value = ColunaD$
x = x + 1
Loop
Close #1
Thank you very much
Pedro Costa
month is "SCNT200703") in a specific location ("C:\Files\").
Is it possible to use : "FileName = Application.GetOpenFilename("All files,
*.*")" but instead of ("All files, *.*") to put in there the exact location
and name of the file?
What i have so far is this:
Path = "C:\Files\"
FicheiroTratar = "SCNT" & Year(Now()) & Month(Now())
Set FicheiroActual = Workbooks.Add
FullName = Path & FicheiroTratar
FileName = Application.GetOpenFilename("All files, *.*")
For I = Len(FileName) To 1 Step -1
If Mid(FileName, I, 1) = "\" Then
FileName = Right(FileName, Len(FileName) - I)
Exit For
End If
Next
Debug.Print FileName
NomeFicheiroOrigem = Left(FileName, 10)
If FileName = "False" Then Exit Sub
x = 1
Open FileName For Input As #1
Do While Not EOF(1)
FicheiroActual.Activate
Input #1, Line$
ColunaA$ = Mid$(Line$, 1, 1)
ColunaB$ = Mid$(Line$, 2, 14)
ColunaC$ = Mid$(Line$, 15, 17)
ColunaD$ = Mid$(Line$, 32, 17)
Worksheets("Sheet1").Cells(x, 1).Value = ColunaA$
Worksheets("sheet1").Columns(2).NumberFormat = "@"
Worksheets("sheet1").Cells(x, 2).Value = ColunaB$
Worksheets("sheet1").Columns(2).NumberFormat = "@"
Worksheets("sheet1").Cells(x, 3).Value = ColunaC$
Worksheets("sheet1").Cells(x, 4).Value = ColunaD$
x = x + 1
Loop
Close #1
Thank you very much
Pedro Costa