サンプルファイル
Public Sub opentextFile()
'=================================
' テキストファイルを読み込む
'=================================
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' 変数
'
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dim myRow As Long
Dim soutaiPath As String
Dim zettaiPath As String
On Error GoTo line
myRow = ActiveCell.Row
soutaiPath = Cells(myRow, "B") '相対パス
zettaiPath = ThisWorkbook.Path & soutaiPath '絶対パス
Label1.Caption = zettaiPath
TextBox1.Text = ""
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' 実際にテキストファイルを読み込む
'
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
fileNum = FreeFile
readData = ""
Open zettaiPath For Input As #fileNum
Do Until EOF(fileNum)
Line Input #fileNum, temp
readData = readData & temp & vbCrLf
Loop
Close #fileNum
TextBox1.Text = readData '
TextBox1.SetFocus
TextBox1.SelStart = 0 'テキストボックスの先頭にカーソルを移動
Exit Sub
line:
Beep
End Sub
|