|
こんにちは
テキストファイルは「テーブル.txt」という名前でマクロブックと同じフォルダ。
項目間の区切りはタブ。
表示のタイミングはCommandButton1をクリックした時。
として作ってみました。^d^
===== UserForm1モジュール =====
Option Explicit
Private Dic As Object
Private Sub UserForm_Initialize()
Dim myPath As String
Dim N As Integer
Dim D As String
Dim Itm As Variant
Set Dic = CreateObject("Scripting.Dictionary")
myPath = ThisWorkbook.Path & "\テーブル.txt"
N = FreeFile
Open myPath For Input As #N
Do Until EOF(N)
Line Input #N, D
Itm = Split(D, vbTab)
Dic.Item(CStr(Itm(0))) = Itm
Loop
Close #N
End Sub
Private Sub CommandButton1_Click()
Dim V As Variant
With Me
If Dic.Exists(.TextBox1.Value) Then
V = Dic.Item(.TextBox1.Value)
.TextBox2.Value = V(1)
.TextBox3.Value = V(2)
.TextBox4.Value = V(3)
Else
.TextBox2.Value = ""
.TextBox3.Value = ""
.TextBox4.Value = ""
End If
End With
End Sub
Private Sub UserForm_Terminate()
Set Dic = Nothing
End Sub
|
|