|
Re: 跟我学excel中的VBA
QUOTE Created By 夏大 At 2005-6-7
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} FrmBookmark
Caption = "书签"
ClientHeight = 3585
ClientLeft = 45
ClientTop = 330
ClientWidth = 5955
OleObjectBlob = "FrmBookmark.frx":0000
StartUpPosition = 1 '所有者中心
End
Attribute VB_Name = "FrmBookmark"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private m_colBookmarks As Collection
Private Sub CmbAdd_Click()
LbxBookmark.AddItem Trim(TxbName)
m_colBookmarks.Add Selection
Unload Me
End Sub
Private Sub CmbClose_Click()
Unload Me
End Sub
Private Sub CmbDelete_Click()
m_colBookmarks.Remove LbxBookmark.ListIndex + 1
LbxBookmark.RemoveItem LbxBookmark.ListIndex
CmbDelete.Enabled = False
CmbLocate.Enabled = False
End Sub
Private Sub CmbLocate_Click()
On Error Resume Next
m_colBookmarks(LbxBookmark.ListIndex + 1).Select
End Sub
Private Sub LbxBookmark_Click()
CmbDelete.Enabled = True
CmbLocate.Enabled = True
End Sub
Private Sub LbxBookmark_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
CmbLocate_Click
End Sub
Private Sub TxbName_Change()
CmbAdd.Enabled = Trim(TxbName) <> "" And Not Selection Is Nothing
End Sub
Private Sub UserForm_Click()
End Sub
Private Sub UserForm_Initialize()
On Error GoTo ErrHandler
Dim iFreeFile As Integer
Dim strTemp As String
Dim nPost As Long
Dim bOk As Boolean
Set m_colBookmarks = New Collection
iFreeFile = FreeFile
If Dir("c:\bookmark.txt") <> "" Then
Open "c:\bookmark.txt" For Input As #iFreeFile
While Not EOF(iFreeFile)
Line Input #iFreeFile, strTemp
nPost = InStr(strTemp, ",")
bOk = True
If nPost > 0 Then
m_colBookmarks.Add Range(Right(strTemp, Len(strTemp) - nPost))
If bOk Then LbxBookmark.AddItem Left(strTemp, nPost - 1)
Else
m_colBookmarks.Add Range(strTemp)
If bOk Then LbxBookmark.AddItem strTemp
End If
Wend
Close #iFreeFile
End If
Exit Sub
ErrHandler:
bOk = False
Resume Next
End Sub
Private Sub UserForm_Terminate()
On Error GoTo ErrHandler
Dim iFreeFile As Integer
Dim i As Long
iFreeFile = FreeFile
Open "c:\bookmark.txt" For Output As #iFreeFile
For i = 1 To m_colBookmarks.Count
Print #iFreeFile, LbxBookmark.List(i - 1) & "," & m_colBookmarks(i).Address
Next i
Close #iFreeFile
Exit Sub
ErrHandler:
Resume Next
End Sub
[M41] |
|