• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Give a MsgBox when nothing is selected

I wrote the following code which aligns all the textboxes that I have selected to the right.

Code:
Sub alignFunction(direction)

Dim oSel As ShapeRange
Set oSel = ActiveWindow.Selection.ShapeRange

With oSel
 .TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = direction
End With

End Sub

Sub AlignRight()
 alignFunction (ppAlignRight)
End Sub

However if I have not selected anything it does not work and gives an error. I would like to include something so I get a pop up saying "Please select anything" in case I didnt select anything.

Any thoughts on how to do this?
 
Hi ,

Can you see if this works ?
Code:
Sub alignFunction(direction)
    Dim oSel As ShapeRange
    Set oSel = ActiveWindow.Selection.ShapeRange
    If oSel Is Nothing Then
      MsgBox "Please select one or more textboxes !", vbExclamation
    Else
      With oSel
            .TextFrame.TextRange.Paragraphs.ParagraphFormat.Alignment = direction
      End With
    End If
End Sub
Narayan
 
Back
Top