N.YAICI
N.YAICI

Reputation: 29

Object Variable or With Block Variable not Set - Macro VBA

I've got an error

Object Variable or With Block Variable not Set

at Set lineProject = c.Row when using the following code:

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

I used he same lines in another macros, to find the ligne of a project using the Libelle.

Thanks for telling what's wrong.

Upvotes: 0

Views: 413

Answers (1)

Pᴇʜ
Pᴇʜ

Reputation: 57693

I guess this the line where you got the error

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

With .Find(Libellé) do you mean Libellé as string or as variable?

If …

  • string then use .Find("Libellé")
  • variable then .Find(Libelle) would be correct.
    Because your variable name is Libelle = ComboBox1.Value

Make sure you use Option Explicit to avoid wrong typed variable names. And declare all your variables before use:

Dim Libelle As String
Libelle = ComboBox1.Value

Upvotes: 2

Related Questions