0

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.

2
  • Where do you get the error? Commented Mar 5, 2018 at 9:35
  • I get this error : Object Variable or With Block Variable not Set Commented Mar 5, 2018 at 10:25

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

12 Comments

The error comes in this line : Set ligneProjet = c.Row
The error occurs because nothing was found (one line before). Did you read my answer above? This should solve your issue. Use Option Explicit to avoid such errors in the future.
In your comment there is again an accent :) If you are not very precisely we are not able to fix your issues. Try and catch if the value was found or not with If c Is Nothing Then MsgBox "'" & Libelle & "' was not found. Aborting now …": Exit Sub right one line after Set c = …
That means that you searched for Project name but it was not found in the range.
Yes but now i'm searching with MatchCase option on Find function. Thank you again
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.