Open different date of text file

Linda Lo

New Member
Joined
May 15, 2023
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Dear all,

I want to open a text file with following but it doesn't work. Please help to point out.

VBA Code:
Dim Ag as Variant

Ag = Format (Cells(2,4), "YYYY-MM-DD")

ChDir: "T:\TEMP\Stock Closing Pr\backup\2024\Ag"
Workbooks.OpenText Filename:_
"T:\TEMP\Stock Closing Pr\backup\2024\" & Ag & "\CTFCLOSPRIC",Origin:=950, StartRow:=1, DataType:=x1FixdWidth, FieldInfo:= Array(0,1), Array(1,1), Array(5,1), TrailingMinusNumbers:= True

Thanks,
Linda
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Are you getting a specific error, or is it just not working?
If you are getting an error, what is the exact error message?

What is the EXACT FULL file path and name of the file?
Does the file have any extension on it (like . TXT, .CSV, .TAB, .DAT, etc)?
 
Upvote 0
I see your VBA code, but no image in the first post.
Do you see an image in the first post?
 
Upvote 0

Forum statistics

Threads
1,215,200
Messages
6,123,598
Members
449,109
Latest member
Sebas8956

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