![]()
筆箱にVBAのカンニングペーパーを入れる係のみすくです。こんにちは。
セルの書式は文字列に設定しています。
'-------------------------------------------------------------------------------
' 【関 数 名】テキストファイル読み込み
' 【処理概要】テキストファイルを読み込み、Excelシート出力する
' 【引 数】[I] ByVal txtFilePath As String テキストファイルパス
' [I] ByVal sh As Worksheet 出力先ワークシートオブジェクト
' [I] ByVal startCellAddress As String 出力先先頭セルアドレスex)A1
' 【戻 り 値】なし
'-------------------------------------------------------------------------------
Public Sub loadTextFileToXlsSheet( _
ByVal txtFilePath As String, ByVal sh As Worksheet, _
ByVal startCellAddress As String)
Dim fn As Integer 'ファイルナンバー
Dim buf As String 'テキスト読込領域
Dim arrTmp() As String 'テキスト読込配列
Dim idx As Long 'カウンタ
Dim endCellAddress As String '貼り付け末尾アドレス
fn = FreeFile
Open txtFilePath For Input As #fn 'ファイルオープン
Do Until EOF(fn)
Line Input #fn, buf
ReDim Preserve arrTmp(idx)
arrTmp(idx) = buf
If idx Mod 1000 = 0 Then
DoEvents
End If
idx = idx + 1
Loop
Close #fn 'ファイルクローズ
'末尾行アドレス取得
endCellAddress = sh.Range(startCellAddress).Offset(idx - 1).Address
With sh.Range(startCellAddress & ":" & endCellAddress)
'セルの表示形式を文字列にする
.NumberFormat = "@"
'値を書き込む
.Value = WorksheetFunction.Transpose(arrTmp)
End With
End Sub
最近のコメント



コメントを残す