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.
 

Some videos you may like

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Code:
'- **PARTIAL CODE **
Dim MyFile As String
MyFile = "C:\Program Files\Compass\" & ActiveSheet.Range("A1").Value
Workbooks.OpenText Filename:=MyFile ' ...........etc.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,270
Messages
5,600,635
Members
414,398
Latest member
dhune

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
Top