OberonPlace.com Forums

OberonPlace.com Forums (http://forum.oberonplace.com/index.php)
-   CorelDRAW/Corel DESIGNER VBA (http://forum.oberonplace.com/forumdisplay.php?f=16)
-   -   SelectionChange Event question (http://forum.oberonplace.com/showthread.php?t=8085)

noj 26-02-2012 18:48

SelectionChange Event question
I am getting a Runtime Error 91 when I close a document (just the document - the application is still open). It doesn't like the following line of code:


If Application.ActiveDocument.Active = False Then Exit Sub
This is the whole lot:


Private Sub GlobalMacroStorage_SelectionChange()

    Dim sr As ShapeRange
    Dim col As String
    Dim colname As OptionButton
    Dim intens As Integer
    Dim siz As Integer
    Set sr = ActiveSelectionRange
    If Application.ActiveDocument.Active = False Then Exit Sub

    If Neon.Visible = False Then
        Exit Sub
        Neon.RU.Value = False
        Neon.RU.ForeColor = &H80000011
        Neon.RE.Value = False
        Neon.RE.ForeColor = &H80000011
        Neon.OG.Value = False
        Neon.OG.ForeColor = &H80000011
        Neon.GO.Value = False
        Neon.GO.ForeColor = &H80000011
        Neon.YE.Value = False
        Neon.YE.ForeColor = &H80000011
        Neon.GR.Value = False
        Neon.GR.ForeColor = &H80000011
        Neon.TU.Value = False
        Neon.TU.ForeColor = &H80000011
        Neon.CY.Value = False
        Neon.CY.ForeColor = &H80000011
        Neon.LI.Value = False
        Neon.LI.ForeColor = &H80000011
        Neon.BL.Value = False
        Neon.BL.ForeColor = &H80000011
        Neon.DE.Value = False
        Neon.DE.ForeColor = &H80000011
        Neon.PU.Value = False
        Neon.PU.ForeColor = &H80000011
        Neon.MA.Value = False
        Neon.MA.ForeColor = &H80000011
        Neon.HO.Value = False
        Neon.HO.ForeColor = &H80000011
        Neon.WH.Value = False
        Neon.WH.ForeColor = &H80000011
        Neon.WA.Value = False
        Neon.WA.ForeColor = &H80000011
        If sr.Count = 0 Then Exit Sub
        If sr(1).IsSimpleShape = True Then Exit Sub
        If Left(sr(1).Name, 4) <> "neon" Then
            Exit Sub
            col = Mid(sr(1).Name, 9, 2)
            Set colname = Neon(Mid(sr(1).Name, 9, 2))
            intens = Mid(sr(1).Name, 11, 3)
            siz = Mid(sr(1).Name, 14, 3)
            Neon.ChangeTest = "Update"
            Neon.Colour = col
            colname.ForeColor = &H8000000E
            Neon.GlowIntensitySlider = intens
            If intens = 0 Then
                Neon.GlowIntensity = "No Glow"
                Neon.GlowIntensity = intens & "%"
            End If
            Neon.GlowSizeSlider = siz
            Neon.GlowSize = siz & "mm"
        End If
    End If
End Sub

Can anyone tell me how to stop errors when the user closes a document?

Also, on a kind-of related matter (is it bad form to ask two questions in one post?), can anyone tell me how to give the main application window back the focus after the above code changes some values on my userform? Instead of the form being selected still?

Thanks heaps.

shelbym 26-02-2012 20:32

You just closed the document, therefore you have no ActiveDocument and that is why you get the error. You could rewrite the line like this:

If ActiveDocument Is Nothing Then Exit Sub
And yes, best to post each question separate as it makes things cleaner and easier to find.

But you can find the answer to your second question here: Passing Control From Modeless Forms


noj 26-02-2012 21:32

That's great. Works perfectly on both accounts. Thanks Shelby.

All times are GMT -5. The time now is 07:08.

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