1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Excelの計算式をテキストファイルに出力してみた

Last updated at Posted at 2016-12-15

--------------
【補足】(2018/10/03)
一つのファイルで比較する。
(参考)winmergeでexcel比較をやってみた。「数式を比較する」も、よさそう。
https://qiita.com/mrrclb48z/items/3ba219b56b92f4d5a482
--------------

(参考)【Excel VBA】セルの内容をテキストファイルに出力するサンプル
http://qiita.com/mono_cat/items/c7c80e3ece0a56505f7d

'Excelの計算式をテキストファイルに出力してみた
'おすすめのフリーソフトがあれば教えて下さい。
'(実行例) 4行  6列目: =MINVERSE(A4:D7)
'(参考)エクセルVBAでテキストファイルに書き出す最も簡単なプログラム
'http://tonari-it.com/vba-txt-print/
'
Sub aaa_Excelの計算式をテキストファイルに出力()
    Dim i As Long
    Dim j As Long
    Dim MaxRow As Long
    Dim MaxCol As Long
    Call 使用済みセル範囲の取得(MaxRow, MaxCol)
'
    Open ActiveWorkbook.Path & "\txt.txt" For Output As #1
    For i = 1 To MaxRow
        n = 0
        For j = 1 To MaxCol
        If Cells(i, j).Formula = "" Then
        Else
            n = n + 1
            Print #1, myFormat(i, MaxRow) & "行" & myFormat(j, MaxCol) & "列目: " & Cells(i, j).Formula
        End If
        Next
        If n > 0 Then Print #1, "'"
    Next
Close
End Sub

Sub 使用済みセル範囲の取得(MaxRow As Long, MaxCol As Long)
    With Range("A1").SpecialCells(xlLastCell)
        MaxRow = .Row
        MaxCol = .Column
    End With
End Sub

Function myFormat(i As Long, n As Long)
    myFormat = Format(i, WorksheetFunction.Rept("@", Len(n) - 1))
End Function
1
1
3

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?