Ошибка method range of object _global failed - VBA (48515)
Формулировка задачи:
Листинг программы
- Dim AAAC As Long
- Dim strSuchen As Variant
- Private Sub ComboBox1_Change()
- If ComboBox1.Value <> "" Then
- strSuchen = ComboBox1.Value
- AAAC = CDbl(Range("A2:A10").Find(What:=strSuchen, lookat:=xlWhole).Row)
- TextBox1.Text = Cells(AAAC, 2)
- TextBox2.Text = Cells(AAAC, 4)
- TextBox3.Text = Cells(AAAC, 5)
- Else
- TextBox1.Text = ""
- TextBox2.Text = ""
- TextBox3.Text = ""
- End If
- End Sub
- Private Sub ComboBox2_Change()
- If ComboBox2.Value <> "" Then
- strSuchen = ComboBox2.Value
- AAAC = CDbl(Range("A2:A40").Find(What:=strSuchen, lookat:=xlWhole).Row)
- TextBox4.Text = Cells(AAAC, 2)
- TextBox5.Text = Cells(AAAC, 4)
- TextBox6.Text = Cells(AAAC, 5)
- Else
- TextBox4.Text = ""
- TextBox5.Text = ""
- TextBox6.Text = ""
- End If
- End Sub
- Private Sub CommandButton2_Click()
- UserForm1.Hide
- End Sub
- Private Sub UserForm_Initialize()
- Dim sFilePath, objXL, Secur
- sFilePath = ActiveDocument.Path & "\qw.xlsx"
- Set objXL = CreateObject("Excel.Application")
- 'objXL.Visible = True
- Set wc = objXL.Workbooks.Open(sFilePath)
- ComboBox1.List = wc.Worksheets("A").Range("A2:A10").Value
- ComboBox2.List = wc.Worksheets("A").Range("A2:A40").Value
- objXL.Quit
- End Sub
Решение задачи: «Ошибка method range of object _global failed»
textual
Листинг программы
- Private Sub UserForm_Initialize()
- With CreateObject("Excel.Application")
- With .Workbooks.Open(ActiveDocument.Path & "\qwe.xlsx", 0)
- ComboBox1.List = .Worksheets("A").Range("A2:D4").Value
- ComboBox2.List = .Worksheets("A").Range("A2:D40").Value
- .Close False
- End With
- .Quit
- End With
- End Sub
- Private Sub ComboBox1_Change()
- LetTextBox ComboBox1
- End Sub
- Private Sub ComboBox2_Change()
- LetTextBox ComboBox2
- End Sub
- Private Sub LetTextBox(comboBox As MSForms.comboBox)
- With comboBox
- If .ListIndex > -1 Then
- TextBox4.Text = .List(.ListIndex, 1)
- TextBox5.Text = .List(.ListIndex, 2)
- TextBox6.Text = .List(.ListIndex, 3)
- Else
- TextBox4.Text = ""
- TextBox5.Text = ""
- TextBox6.Text = ""
- End If
- End With
- End Sub
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д