View Single Post
  #1  
Old 26-02-2012, 19:48
noj noj is offline
Member
 
Join Date: Oct 2011
Location: Sydney
Posts: 31
Default 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:

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

Code:
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
    Else
        
        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
        Else
            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
            colname.SetFocus
            Neon.GlowIntensitySlider = intens
            If intens = 0 Then
                Neon.GlowIntensity = "No Glow"
            Else
                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.
Reply With Quote