0

I've seen in online tutorials Intellisense works the magic: while you key in the object name, it auto complete it for you. Why my VBE doesn't? It works on properties and methods, but not objects.

I'm using Office 2010, maybe the feature is not available in early versions?

ThunderFrame
  • 9,352
  • 2
  • 29
  • 60
Jing Wang
  • 23
  • 4

2 Answers2

2

The Intellisense feature has two requirements:

  1. Compileable Code - Choose menu option Debug..Compile VBA Project to compile. If the project isn't compileable, Intellisense can get confused about when and where to present itself.

  2. Strongly typed variables - Variables and Object Model members must be strongly typed in order for Intellisense to work.

    • None of these variables are strongly typed, so none of them will have Intellisense:

      Dim sht1, sht2 As Variant, sht3 As Object

      Whereas, Dim sht1 As Worksheet will get Intellisense

    • Some object model members, like Excel.ThisWorkbook.Worksheets(1) return a Variant (because the Worksheets method can return a single Worksheet or an array of Worksheets). In order to get Intellisense, you'll need to explicitly declare a strongly typed variable, and then work with that variable:

      'Explicitly declare a strongly typed variable
      Dim sht1 As Worksheet
      'Cast the Variant result to a Worksheet
      Set sht1 = Excel.ThisWorkbook.Worksheets(1)
      With sht1
          'Type a period to invoke Intellisense for the Worksheet object
          Debug.Print .Name
      End With
      

      If you're working with members that return types that are defined in another library, like Excel.Application.VBE, then you'll need to add a reference to that library (in this example, VBIDE) before you can declare an appropriate strongly typed member.

ThunderFrame
  • 9,352
  • 2
  • 29
  • 60
  • Although it doesn't answer my question, what you share is VERY useful. Thanks heaps. – Jing Wang Aug 17 '18 at 02:01
  • If it's been helpful, feel free to upvote the answer. If you have more details about the object that's not providing Intellisense, perhaps edit your original question with the details, and I might be able to help further. – ThunderFrame Aug 17 '18 at 02:04
1

To force Intellisense feature in VBE, simply press Ctrl+Space.

Jing Wang
  • 23
  • 4