Assuming the workbook in question is the ActiveWorkbook, this will work. It get the workbook's full path with FullName
and subsitutes the data file's name for for the workbook's:
Sub test()
Dim wb As Excel.Workbook
Dim strPath As String
Set wb = ActiveWorkbook
strPath = Replace(wb.FullName, wb.Name, "MyFileName.dat")
Dim fnum As Integer
fnum = FreeFile()
Open strPath For Output As #fnum
'my code
Close #fnum
End Sub