facess1202
New Member
- Joined
- Mar 5, 2018
- Messages
- 1
I need to open a text file from a variable file path (which is varied by the month) and then do the text-to-column for the text file. However, the error msg pop out which is stated [Compile error: Named argument not found] when i tried to run the below code in VBA. Anybody can help?
Thank you very much.
Sub abc()
'
FileYear = Year(Date)
MonthOffset = 0
If Day(Date) = 1 Then MonthOffset = 15
FileMonth = Month(Date) - MonthOffset
FileDate = Format(Date - 15, "mm")
FilePath = "W:\interfac\fr_dc\ac\group\cpa" & FileYear & "_" & FileDate & "\gp505b1a.txt"
'
Workbooks.Open (FilePath), Origin:=950, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(7, 1), Array( _
16, 1), Array(24, 1), Array(28, 1), Array(32, 1), Array(36, 1), Array(42, 1), Array(57, 1), _
Array(72, 1), Array(87, 1), Array(91, 1), Array(99, 1), Array(114, 1), Array(128, 1), Array _
(132, 1), Array(145, 1)), TrailingMinusNumbers:=True
Columns("A:R").Select
Selection.Copy
Windows("J020071.xls").Activate
Range("S1").Select
ActiveSheet.Paste
End Sub
Thank you very much.
Sub abc()
'
FileYear = Year(Date)
MonthOffset = 0
If Day(Date) = 1 Then MonthOffset = 15
FileMonth = Month(Date) - MonthOffset
FileDate = Format(Date - 15, "mm")
FilePath = "W:\interfac\fr_dc\ac\group\cpa" & FileYear & "_" & FileDate & "\gp505b1a.txt"
'
Workbooks.Open (FilePath), Origin:=950, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(7, 1), Array( _
16, 1), Array(24, 1), Array(28, 1), Array(32, 1), Array(36, 1), Array(42, 1), Array(57, 1), _
Array(72, 1), Array(87, 1), Array(91, 1), Array(99, 1), Array(114, 1), Array(128, 1), Array _
(132, 1), Array(145, 1)), TrailingMinusNumbers:=True
Columns("A:R").Select
Selection.Copy
Windows("J020071.xls").Activate
Range("S1").Select
ActiveSheet.Paste
End Sub