Why am I getting an "Object required" Here? (1 Viewer)

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 08:22
Joined
Mar 22, 2009
Messages
790
Code:
Sub Greenstar()
Dim myobj As New PowerPoint.Application
Dim temp As Variant
DoCmd.OutputTo acOutputReport, "Greenstar", acFormatXLS, CurrentProject.Path & "\Greenstar.xls"
Excel.Application.Visible = True
Workbooks.Open (CurrentProject.Path & "\Greenstar.xls")
myobj.Visible = msoCTrue
myobj.Presentations.Open (CurrentProject.Path & "\star.pptx")
myobj.ActivePresentation.Slides(1).Shapes(1).Copy
ReDim temp(5)
For Each cell In Range(Rows(2), Rows(Cells.SpecialCells(xlCellTypeLastCell).Row)).Cells.SpecialCells(xlCellTypeConstants).Cells
   Select Case cell.Column
        Case 1
            'ReDim Preserve temp(0)
            Set temp(0) = myobj.Presentations.Add
        Case 2
            'ReDim Preserve temp(1)
            Set temp(1) = temp(0).Slides.Add(temp(0).Slides.Count + 1, ppLayoutBlank)
        Case 3
            'ReDim Preserve temp(2) 'Country_Code
            If temp(1).Shapes.Count = 0 Then Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 15, 100, 10) Else Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, temp(4).Top + temp(4).Height + 15, 100, 10)
            temp(2).TextFrame.TextRange.Text = cell.value
        Case 4
            'ReDim Preserve temp(3) 'Process_Name
            Set temp(4) = temp(1).Shapes.Paste
            If temp(1).Shapes.Count = 1 Or cell.Offset(-1, -1).value <> "" Then
                Set temp(3) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, temp(2).Top + 15, 200, 10)
                 With temp(4)
                    .Left = 10
                    .Top = temp(3).Top + 15
                End With
            Else
                Set temp(3) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, temp(3).Left + temp(3).Width, temp(2).Top + 15, 200, 10)
                With temp(4)
                   .Left = temp(3).Left
                   .Top = temp(3).Top + 15
                End With
            End If
            temp(3).TextFrame.TextRange.Text = cell.value
   End Select
Next cell
End Sub

why am I getting a Run-time error '424'
Object required
in the else section of the code below:
Code:
If temp(1).Shapes.Count = 0 Then Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 15, 100, 10) Else Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, temp(4).Top + temp(4).Height + 15, 100, 10)
 

pr2-eugin

Super Moderator
Local time
Today, 03:52
Joined
Nov 30, 2011
Messages
8,494
For starters, it should be.
Code:
If temp(1).Shapes.Count = 0 Then 
    Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 15, 100, 10) 
Else 
    Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, temp(4).Top + temp(4).Height + 15, 100, 10)
End If
Then you do not "Set" an Array, you only Set objects. The keyword is not needed there. Also without Dimming the dimension, the temp(index) will throw a "Index out of bound" error. So use ReDim or Dim it accordingly.
 

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 08:22
Joined
Mar 22, 2009
Messages
790
Thanks to your reply Paul. My question is to why temp(4) expires when it comes to Case 3?
On the Case 4. I am able to set the following properties of that shapes (picture)
With temp(4)
.Left = temp(3).Left
.Top = temp(3).Top + 15
End With
but when it comes to Case 3 again, I am not able to read the same properties set to it.
Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, temp(4).Top + temp(4).Height + 15, 100, 10)
 

prabha_friend

Prabhakaran Karuppaih
Local time
Today, 08:22
Joined
Mar 22, 2009
Messages
790
Surprise!

Don't know why it is working now?

Code:
Sub Greenstar()
Dim myobj As New PowerPoint.Application
Dim temp As Variant
DoCmd.OutputTo acOutputReport, "Greenstar", acFormatXLS, CurrentProject.Path & "\Greenstar.xls"
Excel.Application.Visible = True
Workbooks.Open (CurrentProject.Path & "\Greenstar.xls")
myobj.Visible = msoCTrue
myobj.Presentations.Open (CurrentProject.Path & "\star.pptx")
myobj.ActivePresentation.Slides(1).Shapes(1).Copy
ReDim temp(5)
For Each cell In Range(Rows(2), Rows(Cells.SpecialCells(xlCellTypeLastCell).Row)).Cells.SpecialCells(xlCellTypeConstants).Cells
Select Case cell.Column
Case 1
'ReDim Preserve temp(0)
Set temp(0) = myobj.Presentations.Add
Case 2
'ReDim Preserve temp(1)
Set temp(1) = temp(0).Slides.Add(temp(0).Slides.Count + 1, ppLayoutBlank)
Case 3
'ReDim Preserve temp(2) 'Country_Code
If temp(1).Shapes.Count = 0 Then Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, 15, 100, 10) Else Set temp(2) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, temp(4).Top + temp(4).Height + 15, 100, 10)
temp(2).TextFrame.TextRange.Text = cell.value
Case 4
'ReDim Preserve temp(3) 'Process_Name
Set temp(4) = temp(1).Shapes.Paste
If temp(1).Shapes.Count = 1 Or cell.Offset(-1, -1).value <> "" Then
Set temp(3) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, 10, temp(2).Top + 15, 200, 10)
temp(4).Left = 10
Else
Set temp(3) = temp(1).Shapes.AddTextbox(msoTextOrientationHorizontal, temp(3).Left + temp(3).Width, temp(2).Top + 15, 200, 10)
temp(4).Left = temp(3).Left
End If
temp(3).TextFrame.TextRange.Text = cell.value
temp(4).Top = temp(3).Top + 15
End Select
Next cell
End Sub

Just removed the with block and entered like this:

temp(4).Left = temp(3).Left
temp(4).Top = temp(3).Top + 15

It Does make a Difference? I want to the rootcause of it. Can anyone help me understand. Are these two different?

Code:
With temp(4)
.Left = temp(3).Left
.Top = temp(3).Top + 15
End With

Code:
temp(4).Left = temp(3).Left
temp(4).Top = temp(3).Top + 15
 

Users who are viewing this thread

Top Bottom