VBA Question - open file in variable path based on the current month and then text to column(FixedWidth)

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
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top