VBA Code for Opening a .dat file from Excel

Ken Monville

New Member
Joined
Mar 31, 2006
Messages
3
I recorded a macro in Excel to open a specific .dat file. The .dat files are named in YYYYMMDD_XXX format and are specific to a calibration event. Normally the XXX is represented by 000. For this example I am using 20080718_000.

The code from the recorded Macro is:

ChDir "C:\Program Files\Compass"
Workbooks.OpenText Filename:="C:\Program Files\Compass\20080718_000.dat", _
Origin:=xlWindows, StartRow:=39, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=True, _
Comma:=False, Space:=False, Other:=False
End Sub

What I want to do is to change the 20080718_000 to a variable so that the Macro will retrieve the variable from a block in the spreadsheet, say A1 (or a UserForm), then put that value in where the 20080718_000 is now.

Any ideas would be greatly appreciated.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Code:
'- **PARTIAL CODE **
Dim MyFile As String
MyFile = "C:\Program Files\Compass\" & ActiveSheet.Range("A1").Value
Workbooks.OpenText Filename:=MyFile ' ...........etc.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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