我要实现当鼠标移到图片框的某一区域,读Excel表中的数据,并用文本框显示出来,
Option Explicit
Private Sub Form_load()
    Text1.Width = 2000
    Text1.Height = 300
    Text1.BackColor = &HC0FFFF
    Text1.Appearance = 0
    Text1.Visible = False
End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Text1.Visible = False
    
End SubPrivate Sub picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
 
    Picture1.PSet (1100, 2100), vbRed
    Dim str1     As String
   Dim Xl     As Object
    Dim K     As New Excel.Application
    Set Xl = K.Workbooks.Open("C:\123.XLS")
str1 = Xl.Worksheets(1).Cells(2, 1).Value
  Text1.Text = str1
  If X > 1000 And X < 1200 And Y > 2000 And Y < 2200 Then
    Text1.Visible = True
Else
    Text1.Visible = False
End If
End Sub
怎么运行时显示“操作系统当前的配置不能运行此程序”而且我要关掉时显示“部件要求挂起”
请大家教教我怎么该啊?感谢了!

解决方案 »

  1.   

    Dim K     As New Excel.Application
    Set Xl = K.Workbooks.Open("C:\123.XLS")
    str1 = Xl.Worksheets(1).Cells(2, 1).Value
    这些不要放在mousemove事件中。mousemove事件是会非常频繁产生的……
      

  2.   

    那么那段程序放在哪个事件中啊,在mousemove事件中要用到str1里面的数据啊。
      

  3.   

    从程序上看str1只是Excel文件中一个单元格的值,可以在Form_Load事件中打开Excel值并取出保存在一个窗体级的变量中。总之不要频繁使用Excel.Application对象,程序会吃不消的。
      

  4.   

    是的,我试出来了,真的感谢,但是如果图片框中要有两个这种区域都实现这种功能,就好象很难实行了,比如还有一个区域(x轴500到700,y轴1500到1700),当鼠标指到这个区域时,显示
    Excel表中cell(2,2)中的数据。这怎么处理呢?再请你帮一下忙。Option Explicit
    Private Sub Form_load()
        Text1.Width = 2000
        Text1.Height = 300
        Text1.BackColor = &HC0FFFF
        Text1.Appearance = 0
        Text1.Visible = False
         Dim str1     As String
       Dim Xl     As Object
        Dim K     As New Excel.Application
        Set Xl = K.Workbooks.Open("C:\123.XLS")
        str1 = Xl.Worksheets(1).Cells(2, 1).Value
        Text1.Text = str1
    End SubPrivate Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        
        Text1.Visible = False
        
    End SubPrivate Sub picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
     Dim str1     As String
       Dim Xl     As Object
        Picture1.PSet (1100, 2100), vbRed
      If X > 1000 And X < 1200 And Y > 2000 And Y < 2200 Then
        Text1.Visible = True
    Else
        Text1.Visible = False
    End If
    End Sub
      

  5.   

    哦,你的意思我明白,但是怎么在Form_load事件中,把Excel表中的数据读入数组中啊,你能不能教我一下,或者推荐我一些资料啊。