ExcelVBA/CSVなど表形式のデータをLDIFなどの形式に変換するためのマクロ
の編集
https://sundays.ddns.net/?ExcelVBA/CSV%E3%81%AA%E3%81%A9%E8%A1%A8%E5%BD%A2%E5%BC%8F%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%82%92LDIF%E3%81%AA%E3%81%A9%E3%81%AE%E5%BD%A2%E5%BC%8F%E3%81%AB%E5%A4%89%E6%8F%9B%E3%81%99%E3%82%8B%E3%81%9F%E3%82%81%E3%81%AE%E3%83%9E%E3%82%AF%E3%83%AD
[
トップ
] [
編集
|
差分
|
履歴
|
添付
|
リロード
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
-- 雛形とするページ --
(no template pages)
#navi(../) -CSVなど表形式のデータをLDIFなどの形式に変換するためのマクロ Option Explicit Sub test() Dim varValueData() As Variant '//2次元配列データ Dim strRowData(1000) As String '//1行のデータを連結した1次元配列 Dim strTemp As String Dim m As Long Dim n As Long Dim h As Long varValueData = ThisWorkbook.Worksheets("sheet2").Range("A1:E25").Value '取得できた全データ書き出しと連結格納 'ReDim strRowData(LBound(varValueData, 1) To UBound(varValueData, 1)) h = 1 For m = LBound(varValueData, 1) To UBound(varValueData, 1) For n = LBound(varValueData, 2) To UBound(varValueData, 2) h = h + 1 strTemp = "" Debug.Print "[" & CStr(m) & ":" & CStr(n) & "]" & CStr(varValueData(m, n)) strTemp = CStr(varValueData(m, n)) strRowData(h) = strTemp Debug.Print strTemp Call actPrint(strTemp) Next Next End Sub Function actPrint(strTemp As String) Dim intFF As Integer ' FreeFile値 Const cnsFILENAME = "\SAMPLE.txt" ' FreeFile値の取得(以降この値で入出力する) intFF = FreeFile ' 指定ファイルをOPEN(出力モード) Open ThisWorkbook.Path & cnsFILENAME For Append As #intFF Print #intFF, strTemp Close #intFF Debug.Print strTemp End Function #navi(../)
タイムスタンプを変更しない
#navi(../) -CSVなど表形式のデータをLDIFなどの形式に変換するためのマクロ Option Explicit Sub test() Dim varValueData() As Variant '//2次元配列データ Dim strRowData(1000) As String '//1行のデータを連結した1次元配列 Dim strTemp As String Dim m As Long Dim n As Long Dim h As Long varValueData = ThisWorkbook.Worksheets("sheet2").Range("A1:E25").Value '取得できた全データ書き出しと連結格納 'ReDim strRowData(LBound(varValueData, 1) To UBound(varValueData, 1)) h = 1 For m = LBound(varValueData, 1) To UBound(varValueData, 1) For n = LBound(varValueData, 2) To UBound(varValueData, 2) h = h + 1 strTemp = "" Debug.Print "[" & CStr(m) & ":" & CStr(n) & "]" & CStr(varValueData(m, n)) strTemp = CStr(varValueData(m, n)) strRowData(h) = strTemp Debug.Print strTemp Call actPrint(strTemp) Next Next End Sub Function actPrint(strTemp As String) Dim intFF As Integer ' FreeFile値 Const cnsFILENAME = "\SAMPLE.txt" ' FreeFile値の取得(以降この値で入出力する) intFF = FreeFile ' 指定ファイルをOPEN(出力モード) Open ThisWorkbook.Path & cnsFILENAME For Append As #intFF Print #intFF, strTemp Close #intFF Debug.Print strTemp End Function #navi(../)
テキスト整形のルールを表示する