Consulting

Results 1 to 4 of 4

Thread: Solved: How to get active item - regardless whether in inspector or explorer

  1. #1

    Solved: How to get active item - regardless whether in inspector or explorer

    I want to call a sub on the (first) active item, like this:

    [vba] itm = IIf(inspector_window_is_active, _
    ActiveInspector.CurrentItem, _
    ActiveExplorer.Selection.Item(1))
    [/vba]
    How to get inspector_window_is_active?

  2. #2
    VBAX Expert JP2112's Avatar
    Joined
    Oct 2008
    Location
    Astoria, NY
    Posts
    590
    Location
    I think you mean this:

    [vba]Sub Test()
    Set itm = GetCurrentItem
    End Sub[/vba]

    [vba]Function GetCurrentItem() As Object
    ' returns reference to current item, either the one
    ' selected (Explorer), or the one currently open (Inspector)
    Select Case True
    Case IsExplorer(Application.ActiveWindow)
    Set GetCurrentItem = ActiveExplorer.Selection.Item(1)
    Case IsInspector(Application.ActiveWindow)
    Set GetCurrentItem = ActiveInspector.CurrentItem
    End Select
    End Function
    Function IsExplorer(itm As Object) As Boolean
    IsExplorer = (TypeName(itm) = "Explorer")
    End Function
    Function IsInspector(itm As Object) As Boolean
    IsInspector = (TypeName(itm) = "Inspector")
    End Function[/vba]
    Regards,
    JP

    Read the FAQ
    Getting free help on the web
    My website
    Please use [vba][/vba] tags when posting code

  3. #3
    What a great reply! Not only did I get a solution for my problem, but I also learned a cool way to use a Case statement. And, of course, you're right that I would need Set for the assignment of an object.

  4. #4
    VBAX Newbie
    Joined
    Jun 2018
    Posts
    1
    Location
    Thanks a lot for posting this code. It really helped me a lot and I also learned from the Case method you have used.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •