Dim excel As Object
Set excel = CreateObject("excel.application")
excel.Visible = True
Dim wb As Object
Set wb = excel.workbooks.open(App.Path & "\Book1.xlsx")
Dim ws As Object
Set ws = wb.sheets(1)
Dim blnFound As Boolean
blnFound = False
Dim i As Long
i = 3
Do While ws.cells(i, "A") <> ""
If InStr(1, ws.cells(i, "A"), txt定損地點關鍵字.Text, vbTextCompare) > 0 Then
txt查詢定損地點.Text = ws.cells(i, "A").Value
txt查詢賬號后六位.Text = ws.cells(i, "B").Value
txt查詢開戶行縮寫.Text = ws.cells(i, "C").Value
blnFound = True
Exit Do
End If
Loop
wb.Close
excel.quit
If Not blnFound Then
MsgBox "未找到匹配資訊!", vbExclamation
End If
End Sub
Private Sub cmd添加_Click()
Const xlDown As Long = -4121
Dim excel As Object
Set excel = CreateObject("excel.application")
excel.Visible = True
Dim wb As Object
Set wb = excel.workbooks.open(App.Path & "\Book1.xlsx")
Dim ws As Object
Set ws = wb.sheets(1)
Dim row As Long
row = ws.UsedRange.End(xlDown).row + 1
Dim excel As Object
Set excel = CreateObject("excel.application")
excel.Visible = True
Dim wb As Object
Set wb = excel.workbooks.open(App.Path & "\Book1.xlsx")
Dim ws As Object
Set ws = wb.sheets(1)
Dim blnFound As Boolean
blnFound = False
Dim i As Long
i = 3
Do While ws.cells(i, "A") <> ""
If InStr(1, ws.cells(i, "A"), txt定損地點關鍵字.Text, vbTextCompare) > 0 Then
txt查詢定損地點.Text = ws.cells(i, "A").Value
txt查詢賬號后六位.Text = ws.cells(i, "B").Value
txt查詢開戶行縮寫.Text = ws.cells(i, "C").Value
blnFound = True
Exit Do
End If
i = i + 1
Loop
wb.Close
excel.quit
If Not blnFound Then
MsgBox "未找到匹配資訊!", vbExclamation
End If
End Sub
Private Sub cmd添加_Click()
Const xlDown As Long = -4121
Dim excel As Object
Set excel = CreateObject("excel.application")
excel.Visible = True
Dim wb As Object
Set wb = excel.workbooks.open(App.Path & "\Book1.xlsx")
Dim ws As Object
Set ws = wb.sheets(1)
Dim row As Long
row = ws.UsedRange.End(xlDown).row + 1
Dim ctr, Rn As Long
Dim oe, ob As Object
Dim fn, fns, sh As String
Private Sub Form_Load()
Set oe = CreateObject("Excel.application")
oe.DisplayAlerts = False
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set oe = Nothing
End Sub
Private Sub 已選_Change()
Set ob = oe.workbooks.Open(已選)
sh = ob.Sheets(1).Name
Rn = oe.application.counta(ob.Sheets(1).Columns(1))
ob.Close
Set ob = Nothing
If Len(已選) > 0 Then
搜索框.Enabled = True
添加按鍵.Enabled = True
Else
搜索框.Enabled = False
添加按鍵.Enabled = False
End If
Call 查找
End Sub
Private Sub 拖入框_Click()
已選 = 拖入框
i = InStrRev(拖入框, "\")
fn = Mid(拖入框, i + 1, Len(拖入框) - i)
fns = Left(拖入框, i)
End Sub
Private Sub 拖入框_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
For i = 1 To Data.Files.Count
拖入框.AddItem Data.Files(i)
Next
End Sub
Private Sub 搜索框_Change()
If Len(搜索框) = 0 Then
定損地點框 = ""
賬號后六位 = ""
開戶行縮寫 = ""
End If
End Sub
Sub 查找()
On Error Resume Next
If Len(已選) > 0 And Len(搜索框) > 0 Then
定損地點框 = ""
賬號后六位 = ""
開戶行縮寫 = ""
For ctr = 1 To Rn
ed = oe.ExecuteExcel4Macro("'" & fns & "[" & fn & "]" & sh & "'!R" & ctr & "C1")
If InStr(ed, 搜索框) > 0 Then
定損地點框 = ed
賬號后六位 = oe.ExecuteExcel4Macro("'" & fns & "[" & fn & "]" & sh & "'!R" & ctr & "C" & 2)
開戶行縮寫 = oe.ExecuteExcel4Macro("'" & fns & "[" & fn & "]" & sh & "'!R" & ctr & "C" & 3)
Exit Sub
End If
Next ctr
MsgBox "找不到目標", vbInformation
End If
End Sub
Private Sub 添加按鍵_Click()
On Error Resume Next
If Len(已選) > 0 And Len(定損地點添加) > 0 And Len(開戶行) > 0 And Len(賬號) > 0 Then
Set ob = oe.workbooks.Open(已選)
Rctr = oe.application.counta(ob.Sheets(1).Columns(1)) + 1
ob.Sheets(1).cells(Rctr, 1) = 定損地點添加
ob.Sheets(1).cells(Rctr, 4) = 開戶行
ob.Sheets(1).cells(Rctr, 5) = 賬號
ob.Sheets(1).cells(Rctr - 1, 2).Resize(2, 2).filldown
Rn = Rn + 1
ob.save
ob.Close
Set ob = Nothing
MsgBox "添加完成"
定損地點添加 = ""
開戶行 = ""
賬號 = ""
Else
MsgBox "請先填寫完資訊", vbCritical
End If
End Sub
Private Sub 搜索按鍵_Click()
Call 查找
End Sub
Private Sub 搜索框_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 13 Then Call 查找
End Sub