对象变量或未设置块变量 - 宏VBA

问题描述 投票:0回答:1

我有一个错误

对象变量或未设置块变量

Set lineProject = c.Row使用以下代码时:

Private Sub CommandButton1_Click()

Dim pptFile As Object

Dim ppres As PowerPoint.Presentation

Path = "\\FSCFFACT\Activites\CFF DOMO GP ACT\Tableau de Bord\" 

Set pptFile = CreateObject("Powerpoint.application")

If ComboBox1.Value <> "" Then

        CODOMO.Hide

        Libelle = ComboBox1.Value

        lastline = Worksheets("Projets").Cells(Worksheets("Projets").Rows.Count, "B").End(xlUp).Row

        Set c = Worksheets("Projets").Range("B10:B" & lastline).Find(Libelle)

        Set lineProject = c.Row

        pptFile.Presentations.Open (Path & "Modèle CODOMO.pptx")

        Set pppres = pptFile.ActivePresentation

    Else
        ...        
    End If
End Sub

我在另一个宏中使用了相同的行,使用Libelle查找项目的行。

谢谢你说出了什么问题。

excel excel-vba vba
1个回答
2
投票

我猜这是你得到错误的那一行

Set c = Worksheets("Projets").Range("B10:B" & lastline).Find(Libellé)

使用.Find(Libellé)你的意思是Libellé是字符串还是变量?

如果...

  • 然后使用.Find("Libellé")字符串
  • 变量然后.Find(Libelle)将是正确的。 因为你的变量名是Libelle = ComboBox1.Value

确保使用Option Explicit以避免输入错误的变量名称。并在使用前声明所有变量:

Dim Libelle As String
Libelle = ComboBox1.Value
© www.soinside.com 2019 - 2024. All rights reserved.