有大神能帮忙做一个VB窗口,数据来自已有的excel文件,我想在VB窗口输入人名确定后出现这一整行的数据

给个模板程序... 给个模板程序 展开
 我来答
zgwxm
2011-08-19 · TA获得超过2.1万个赞
知道大有可为答主
回答量:3567
采纳率:87%
帮助的人:2619万
展开全部
'首先要将“工程-引用”中的Mic… Excel…选中
'在窗体上添加5个文本框(如果需要,可以再增多)和两个按钮
Dim StrTg As String
Dim xlApp As Excel.Application
Private Sub Command1_Click()
Set xlApp = New Excel.Application
Set xlApp = CreateObject("Excel.Application")
On Error Resume Next
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(App.Path & "\1.xls")
'打开存在数据的Excdl文件
If IntHs(Text1.Text) = 0 Then
MsgBox "没找到符合的记录!"
Else
Text2 = xlApp.Worksheets("Sheet1").Range("A1").Cells(IntHs(Text1.Text), 2)
Text3 = xlApp.Worksheets("Sheet1").Range("A1").Cells(IntHs(Text1.Text), 3)
Text4 = xlApp.Worksheets("Sheet1").Range("A1").Cells(IntHs(Text1.Text), 4)
Text5 = xlApp.Worksheets("Sheet1").Range("A1").Cells(IntHs(Text1.Text), 5)
End If
'xlBook.Save
'xlApp.Save
ActiveWorkbook.Close
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
End Sub
Private Function IntHs(StrYssj As String, Optional Mh As Integer) As Integer
Dim Czbj As Boolean
Dim StrT As String
Dim I As Integer
Mh = 0
I = 0
Czbj = False
Do While Czbj = False
I = I + 1
StrT = xlApp.Worksheets("Sheet1").Range("A1").Cells(I, 1)
If xlApp.Worksheets("Sheet1").Range("A1").Cells(I, 1) = StrYssj Then
IntHs = I
Czbj = True
ElseIf Trim(xlApp.Worksheets("Sheet1").Range("A1").Cells(I, 1)) = "" Then
IntHs = 0
Czbj = True
Mh = I - 1
End If
Loop
End Function
Private Sub Command2_Click()
Dim Zhhs As Integer
Dim Jlhs As Integer
Set xlApp = New Excel.Application
Set xlApp = CreateObject("Excel.Application")
On Error Resume Next
xlApp.Visible = False
Set xlBook = xlApp.Workbooks.Open(App.Path & "\1.xls")
Jlhs = IntHs(Text1.Text, Zhhs)
If Jlhs > 0 Then
xlApp.Worksheets("Sheet1").Range("A1").Cells(Jlhs, 2) = Text2
xlApp.Worksheets("Sheet1").Range("A1").Cells(Jlhs, 3) = Text3
xlApp.Worksheets("Sheet1").Range("A1").Cells(Jlhs, 4) = Text4
xlApp.Worksheets("Sheet1").Range("A1").Cells(Jlhs, 5) = Text5
MsgBox "修改成功!"
ElseIf Zhhs > 0 Then
Zhhs = Zhhs + 1
xlApp.Worksheets("Sheet1").Range("A1").Cells(Zhhs, 1) = Text1
xlApp.Worksheets("Sheet1").Range("A1").Cells(Zhhs, 2) = Text2
xlApp.Worksheets("Sheet1").Range("A1").Cells(Zhhs, 3) = Text3
xlApp.Worksheets("Sheet1").Range("A1").Cells(Zhhs, 4) = Text4
xlApp.Worksheets("Sheet1").Range("A1").Cells(Zhhs, 5) = Text5
MsgBox "新记录创建成功!"
End If
xlBook.Save
'xlApp.Save
ActiveWorkbook.Close
xlBook.Close (True)
xlApp.Quit
Set xlApp = Nothing
End Sub
沙慧月03
2011-08-20 · TA获得超过2156个赞
知道大有可为答主
回答量:2717
采纳率:100%
帮助的人:3593万
展开全部
我这简单,假设姓名在第一列
Private Sub Command1_Click()
Set oleExcel = CreateObject("Excel.Application")
oleExcel.Visible = False
oleExcel.Workbooks.Open ("c:\数据.xls")

a = InputBox("请输入姓名")

Do
hang = hang + 1
If oleExcel.Worksheets("Sheet1").Cells(hang, 1) = "" Then Exit Do
Loop

Do‘修改1,改变姓名所在列数
lie = lie + 1
If oleExcel.Worksheets("Sheet1").Cells(lie, 1) = "" Then Exit Do
z = oleExcel.Worksheets("Sheet1").Cells(lie, 1)
If z = a Then
For i = 1 To hang - 1
temp = temp & oleExcel.Worksheets("Sheet1").Cells(lie, i) & Space(1)
Next
MsgBox temp
Exit Do
End If
Loop

oleExcel.Quit
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式