Trying to understand "Invalid qualifier" error

  • Thread starter Thread starter Mike Frith
  • Start date Start date
M

Mike Frith

Hi,

I have the following code that cycles through the slides, finds all the
textboxes on each slide and tries to get the first four characters of text.
But the error I get is "Invalid qualifier" on the line indicated below and
"theText" is highlighted. I'm sure it's something simple but I have no idea.
Can anyone clue me in?

thanks
Mike

Sub SaveData()

Dim theDirectory As Presentation
Set theDirectory = Application.Presentations(1)
Dim theSlides As Slides
Set theSlides = theDirectory.Slides

Dim slideCount As Long
slideCount = theSlides.Count()

Dim strClub As String
Dim theText As String
Dim strLength As Long

For i = 1 To slideCount
Dim shapeCount As Long
shapeCount = theSlides(i).shapes.Count

For j = 1 To shapeCount
If theSlides(i).shapes(j).Type = msoTextBox Then
theText = theSlides(i).shapes(j).TextFrame.TextRange.Text
If theText.Left(4) = "Club" Then <----------- error here
strClub = theText.Left(4)
End If
Next j
Next i

End Sub
 
Mike,
'theText' is not an object, it is a string variable. There are not methods
associated with it. Hence the error. I've corrected it and also the IF-ENDIF
construct wasn't complete.

' ----- Beginning Of Code -----
Option Explicit

Sub SaveData()
Dim I As Integer
Dim J As Integer

Dim theDirectory As Presentation
Set theDirectory = Application.Presentations(1)
Dim theSlides As Slides
Set theSlides = theDirectory.Slides

Dim slideCount As Long
slideCount = theSlides.Count()

Dim strClub As String
Dim theText As String
Dim strLength As Long
Dim shapeCount As Long

For I = 1 To slideCount
shapeCount = theSlides(I).Shapes.Count
For J = 1 To shapeCount
If theSlides(I).Shapes(J).Type = msoTextBox Then
If theSlides(I).Shapes(J).TextFrame.HasText Then
theText = theSlides(I).Shapes(J).TextFrame.TextRange.Text
If Left(theText, 4) = "Club" Then
strClub = Left(theText, 4)
End If
End If
End If
Next J
Next I
End Sub
' ----- End Of Code -----
--
Regards
Shyam Pillai

Batch Exporter
http://www.mvps.org/skp/products/xport/
 
Thanks Shyam,

Mike

Shyam Pillai said:
Mike,
'theText' is not an object, it is a string variable. There are not methods
associated with it. Hence the error. I've corrected it and also the IF-ENDIF
construct wasn't complete.

' ----- Beginning Of Code -----
Option Explicit

Sub SaveData()
Dim I As Integer
Dim J As Integer

Dim theDirectory As Presentation
Set theDirectory = Application.Presentations(1)
Dim theSlides As Slides
Set theSlides = theDirectory.Slides

Dim slideCount As Long
slideCount = theSlides.Count()

Dim strClub As String
Dim theText As String
Dim strLength As Long
Dim shapeCount As Long

For I = 1 To slideCount
shapeCount = theSlides(I).Shapes.Count
For J = 1 To shapeCount
If theSlides(I).Shapes(J).Type = msoTextBox Then
If theSlides(I).Shapes(J).TextFrame.HasText Then
theText = theSlides(I).Shapes(J).TextFrame.TextRange.Text
If Left(theText, 4) = "Club" Then
strClub = Left(theText, 4)
End If
End If
End If
Next J
Next I
End Sub
' ----- End Of Code -----
--
Regards
Shyam Pillai

Batch Exporter
http://www.mvps.org/skp/products/xport/
 
Back
Top