LoginSignup
1
1

More than 5 years have passed since last update.

【編集中 記事】Excelに記載した進捗報告書を、そのExcelファイルがある場所にテキストファイルとして出力する

Last updated at Posted at 2018-10-28

作成の目的

Excelファイルでなく、テキストファイルで進捗ファイルを提出するように依頼されたため、
マクロを作成した。

Sub ファイル出力を行う()

  ' 出力ファイルのフルパス
  Dim OutputSaki As String

  ' ファイル番号
  Dim FileNum As Integer
  Dim i As Long
  Dim TodayDate As String
  TodayDate = Format(Date, "mmdd")
  OutputSaki = ActiveWorkbook.Path & "\" & TodayDate & "_" & "進捗報告.txt"
  FileNum = FreeFile

  Dim FileAriHantei As Long
  Dim BookPathAndName As String

  BookPathAndName = ThisWorkbook.Path

    If Dir(OutputSaki) <> "" Then
        FileAriHantei = MsgBox("ファイルがすでに存在します" & vbCrLf & _
                    "上書きしますか?", vbYesNo)
        If FileAriHantei = vbNo Then
            Exit Sub
        End If
    End If

  Open OutputSaki For Output As FileNum
  For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
  Print #FileNum, Cells(i, "A").Value & Cells(i, "B").Value
  Next i
  Close FileNum
End Sub
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1