How to write if shape exists in excel vba

Hello,
I am extracting particular color text from a particular column, say Q and pasting it in powerpoint. But the text is from different cell which get pasted in different text box. So i have used macros which will convert the data into one text box. The below code i am using to merge in one text box.
'to merge the textboxes into one text box
With myPresentation.Slides(1).Shapes
'set a reference to the 'master' text box
Set myShape = .Item(1)
'copy text from text boxes to master text box
For x = 2 To .Count
If .Item(x).Type = msoTextBox Then
'insert a carriage return
myShape.TextFrame2.TextRange.InsertAfter vbCrLf
.Item(x).TextFrame2.TextRange.Copy
myShape.TextFrame2.TextRange.InsertAfter(.Item(x).TextFrame2.TextRange).PasteSpecial (msoClipboardFormatNative)
End If
Next
'delete the text boxes that have been copied(must count backwards when deleting items from collections)
For x = .Count To 2 Step -1
.Item(x).Delete
Next
End With

Open in new window


 Likewise, there is some text which too needs to be extracted from different column, say H. I have used the same code for extracting as well merging it into single text box. But it may happen that there is not any text in column H. Using below code it gives me error about the range.

 Set myShape = mySlide.Shapes(mySlide.Shapes.Count)
  'to merge the textboxes into one text box
  With myPresentation.Slides(1).Shapes
'set a refrence to the 'master' text box
Set myShape = .Item(2)
'copy text from text boxes to master text box
For x = 3 To .Count
If .Item(x).Type = msoTextBox Then
'insert a carriage return
myShape.TextFrame2.TextRange.InsertAfter vbCrLf
.Item(x).TextFrame2.TextRange.Copy
myShape.TextFrame2.TextRange.InsertAfter(.Item(x).TextFrame2.TextRange).PasteSpecial (msoClipboardFormatNative)
End If
Next
'delete the text boxes that have been copied(must count backwards when deleting items from collections)
For x = .Count To 3 Step -1
.Item(x).Delete
Next

End With

Open in new window

So, i used the code as If shape>0 then
else
end if
It works but when there is text in column it wont merge the text boxes. I am not able to understand the problem. Please help me out. Thanks in advance
aditeeAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

generic way
Set myShape = Nothing
On Error Resume Next
Set myShape = .Item(1)
On Error Goto 0
if not myShape Is Nothing Then
' there's a shape
Else
' there's no shape
End If

Open in new window

Regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jamie GarrochPowerPoint Consultant & DeveloperCommented:
I'm not sure I fully understand the question but if I answer the question title, then you can find out if there are any shapes on a particular slide like this:

If myPresentation.Slides(1).Shapes.Count > 0 Then

Open in new window


When posting questions, please put code in a code block using the CODE tool in the editor as it makes the question easier to read.
0
TracyVBA DeveloperCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Split:
-- Rgonzo1971 (https:#a42370324)
-- Jamie Garroch (https:#a42370732)


If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

broomee9
Experts-Exchange Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VBA

From novice to tech pro — start learning today.