OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > Code Critique

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 26-12-2007, 11:31
m31uk3
Guest
 
Posts: n/a
Default Object variable or with block variable not set..

So I am getting this error and I am not exactly sure why...

Here is my code. the line it is highlighting is the first line of the if statement...

Code:
Sub AutoAnSPage()
    'Align and Space Selected Objects
    Dim CurSelection As ShapeRange
    
    Set CurSelection = ActiveSelectionRange
    CurSelection.AlignToPage cdrAlignLeft + cdrAlignTop, cdrTextAlignBoundingBox
    CurSelection.Move 0.2, -0.2
    CurSelection.Ungroup
    If CurSelection.Shapes.First.Type = cdrTextShape Then
        CurSelection.Shapes.First.CreateSelection
    Else
        ActiveDocument.ClearSelection
    End If
End Sub
Thanks in advance...
Reply With Quote
  #2  
Old 26-12-2007, 12:37
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,728
Blog Entries: 9
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Check for Objects...

Most likely it means you do no have anything selected. Best to add an error handler to make sure you have something selected. Something like this:
Code:
Sub AutoAnSPage()
    'Align and Space Selected Objects
    Dim CurSelection As ShapeRange
    
    Set CurSelection = ActiveSelectionRange
    
    If CurSelection.Count = 0 Then
        MsgBox "Please Select an Object or Objects.", , "AutoAnPage"
        Exit Sub
    End If
    
    CurSelection.AlignToPage cdrAlignLeft + cdrAlignTop, cdrTextAlignBoundingBox
    CurSelection.Move 0.2, -0.2
    CurSelection.Ungroup
    If CurSelection.Shapes.First.Type = cdrTextShape Then
        CurSelection.Shapes.First.CreateSelection
    Else
        ActiveDocument.ClearSelection
    End If
End Sub
Best of luck,

-Shelby
Reply With Quote
  #3  
Old 26-12-2007, 13:17
m31uk3
Guest
 
Posts: n/a
Default

All that is needed to be said is that you are a wonderful person!

Here is the final code for review:

Code:
Sub AutoAnSPage()
    'Align and Space Selected Objects + (If priority text exists convert it to curves and select it.)
    On Error Resume Next
    ActiveDocument.BeginCommandGroup "AutoAnSPage"
    Dim CurSelection As ShapeRange
    
    Set CurSelection = ActiveSelectionRange

    If CurSelection.count > 0 Then
        CurSelection.AlignToPage cdrAlignLeft + cdrAlignTop, cdrTextAlignBoundingBox
        CurSelection.Move 0.2, -0.2
        
        If CurSelection.Shapes.First.Type = cdrGroupShape Then CurSelection.Ungroup

        If CurSelection.Shapes.First.Type = cdrTextShape Then
            CurSelection.Shapes.First.ConvertToCurves
            CurSelection.Shapes.First.CreateSelection
        Else
            ActiveDocument.ClearSelection
        End If
    Else
        MsgBox "Please select 1 or more object(s).", , "AutoAnSPage"
    End If
    ActiveDocument.EndCommandGroup
End Sub
Many Thanks!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
moving an object down in vba sifterbox CorelDRAW/Corel DESIGNER VBA 1 27-04-2006 14:40
How to select object inside another object jukos General 4 24-10-2005 21:27
Background to object Fine! But Object to Background - How? marian General 2 15-07-2005 03:51
object variable not found graphicdesigner CorelDRAW/Corel DESIGNER VBA 4 22-11-2004 18:13
Bounding lines around an object toy4mud CorelDRAW CS 2 04-11-2004 11:56


All times are GMT -5. The time now is 18:39.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com