|
在网上下的代码,我改了一下,做成功了一个,但这个就是不成功,老提示 Set Wb = Me.Shapes(1).OLEFormat.Object 'Me错误。
不知道哪位高手可以帮我。
Option Explicit
'声明公共变量
Dim Wb As Object, Sh As Object, SouceRng As Object, TarCell As Object
'当控件获得焦点时运行
Private Sub ComboBox1_GotFocus()
Dim i As Integer
'设置Wb为内嵌的Excel工作薄,Sh为指定工作表,SouceRng和TarCell为指定单元格区域
Set Wb = Me.Shapes(1).OLEFormat.Object 'Me表示正在播放的Slide
Set Sh = Wb.worksheets("sheet1")
Set SouceRng = Sh.Range("A4:A48")
Set TarCell = Sh.Range("A1")
With ComboBox1
'先清除列表
If .ListCount > 0 Then
.ListIndex = -1
For i = .ListCount - 1 To 0 Step -1
.RemoveItem i
Next i
End If
'加入列表项
For i = 1 To SouceRng.Count
.AddItem SouceRng.Offset(i - 1, 0).Range("A1")
Next i
'选择第一项
.ListIndex = 0
'修改TarCell单元格中的值
TarCell = .Value
End With
End Sub
Private Sub ComboBox1_LostFocus()
Set TarCell = Nothing
Set SouceRng = Nothing
Set Sh = Nothing
Set Wb = Nothing
End Sub
'‘当控件值改变时运行对内嵌工作薄单元格的改变
Private Sub ComboBox1_Change()
'改变内嵌工作薄中相应单元格的值
TarCell = ComboBox1.Value
End Sub
|
|