คำถามของคุณดีเพราะคุณพยายามแก้ไขปัญหาและแสดงให้เราเห็นว่าคุณได้ลองทำอะไร คำถามของคุณไม่ดีเพราะคุณไม่ได้พูดในสิ่งที่ผิด แมโครของคุณทำงานโดยไม่มีข้อผิดพลาด ฉันคิดว่ามันไม่ได้ทำในสิ่งที่คุณต้องการ แต่คุณไม่ได้บอกเราว่าคุณต้องการอะไร 
 ฉันสร้างแผ่นงานที่ตรงกับมาโครของคุณ: 

 ฉันเอารหัสของคุณและทำการเปลี่ยนแปลงเล็กน้อย: 
-  ฉันเพิ่ม Option Explicitและประกาศตัวแปรทั้งหมด
-  ฉันเพิ่มคำสั่งเพื่อรับชื่อของโฟลเดอร์ที่มีสมุดงานของฉันและเพิ่มชื่อโฟลเดอร์นี้ในคำสั่งเปิด บางทีคุณอาจรวมชื่อเส้นทางในแผ่นงานและไม่ต้องการสิ่งนี้ 
. 
Option Explicit
Sub CreateFile()
  Dim fnum As Long
  Dim MyFile As String
  Dim PathCrnt As String
  PathCrnt = ActiveWorkbook.Path & "\"
  Do While Not IsEmpty(ActiveCell.Offset(0, 1))
    MyFile = PathCrnt & ActiveCell.Value & ".mhd"
    'set and open file for output
    fnum = FreeFile()
    Open MyFile For Output As fnum
    'use Print when you want the string without quotation marks
    Print #fnum, ActiveCell.Offset(0, 5); " " & ActiveCell.Offset(0, 6); " " & _
        ActiveCell.Offset(0, 7); " " & ActiveCell.Offset(0, 8); " " & _
        ActiveCell.Offset(0, 9); " " & ActiveCell.Offset(0, 10); " " & _
        ActiveCell.Offset(0, 11); " " & ActiveCell.Offset(0, 12); " " & _
        ActiveCell.Offset(0, 13); " " & ActiveCell.Offset(0, 14); " " & _
        ActiveCell.Offset(0, 15); " " & ActiveCell.Offset(0, 16); " " & _
        ActiveCell.Offset(0, 17); " " & ActiveCell.Offset(0, 18); " " & _
        ActiveCell.Offset(0, 19); " " & ActiveCell.Offset(0, 20); " " & _
        ActiveCell.Offset(0, 21); " " & ActiveCell.Offset(0, 22); " " & _
        ActiveCell.Offset(0, 23); " " & ActiveCell.Offset(0, 24); " " & _
        ActiveCell.Offset(0, 25); " " & ActiveCell.Offset(0, 26)
    Close #fnum
    ActiveCell.Offset(1, 0).Select
  Loop
End Sub
 แมโครของคุณทำงานโดยไม่มีข้อผิดพลาดและสร้างไฟล์ต่อบรรทัด ฉันเห็นด้วยว่ามันไม่ได้สง่างาม แต่ใช้งานได้หากนี่คือสิ่งที่คุณต้องการ ฉันสงสัยว่าคุณต้องการทุกบรรทัดในไฟล์เดียวหรือไม่ ถ้าเป็นเช่นนั้นคุณต้องเปิดและปิดไฟล์นอกลูป 
 ด้านล่างนี้เป็นรหัสของคุณ แต่ฉันไม่ได้เปลี่ยนสิ่งที่มันทำ ฉันหวังว่านี่จะช่วยได้. กลับมาถ้าคำอธิบายใด ๆ ของฉันไม่ชัดเจน หากสิ่งนี้ไม่ได้ให้ข้อมูลที่เพียงพอแก่คุณในการแก้ปัญหาของคุณคุณจะต้องอธิบายให้ชัดเจนยิ่งขึ้นว่าเกิดอะไรขึ้นกับแมโครของคุณ 
Option Explicit
Sub CreateFile2()
  Dim ColStart As Long
  Dim ColCrnt As Long
  Dim FileLine As String
  Dim FileName As String
  Dim fnum As Long
  Dim MyFile As String
  Dim PathCrnt As String
  Dim RowStart As Long
  Dim RowLast As Long
  Dim RowCrnt As Long
  ' Your code starts at the active cell.  This relies on the user leaving
  ' the cursor in the correct cell of the correct worksheet.  I have left
  ' the macro like this but have made it more explicit.
  ColStart = ActiveCell.Column
  RowStart = ActiveCell.Row
  PathCrnt = ActiveWorkbook.Path & "\"
  ' My code does  not move the cursor and operates on the worksheet
  ' identified in the With statement.  I have used the active worksheet
  ' but I could have written 'With Worksheets("Sheet2")' or
  ' made the worksheet name a variable.
  With ActiveSheet
    ' Cells(R,C) identifies a cell within the active worksheet by its row
    ' and column number.
    ' .Cells(R,C) identifies a cell within the worksheet named in the With
    ' statement by its row and column number.
    ' Rows.Count gives the maximum row number in your version of Excel.
    ' This statement starts at the bottom of column ColStart, moves up until
    ' it reaches a cell with a value and returns its row number.
    ' With this I could write:
    '    For RowCrnt = RowStart to RowLast
    '       -----
    '    Next
    ' I have kept your style.  But I suggest you experiment with Ctrl+Up,
    ' which is the keyboard equivalent of this VBA and look up "End" in
    ' VBA help.
    RowLast = .Cells(Rows.Count, ColStart).End(xlUp).Row
    RowCrnt = RowStart
    Do While Not IsEmpty(.Cells(RowCrnt, ColStart).Value)
      ' This is not necessary; I can use .Cells(RowCrnt, ColStart).Value
      ' in the file open statment.  But this makes it clearer what I am
      ' doing.  When you need to update this macro in six or twelve
      ' months you will immediately see what the macro is doing.
      FileName = .Cells(RowCrnt, ColStart).Value
      ' Why the extension "MHD"?  It is easier to stick to standard
      ' extensions.
      MyFile = PathCrnt & FileName & ".mhd"
      'set and open file for output
      fnum = FreeFile()
      Open MyFile For Output As fnum
      ' There are lots of different ways of concatenating the cells in
      ' a row.  I will not claim this is the best but I think it is easy
      ' to understand.  Having it in a loop means it is easy to change
      ' the number of columns written to the file.
      FileLine = .Cells(RowCrnt, 6).Value
      For ColCrnt = 7 To 27
        FileLine = FileLine & " " & .Cells(RowCrnt, ColCrnt).Value
      Next
      Print #fnum, FileLine
      Close #fnum
      RowCrnt = RowCrnt + 1
    Loop
  End With
End Sub