问题
If I am writing an argument in Excel-hosted VBA, for example
ActiveSheet.UsedRange.Select
Halfway through writing the first part -- ActiveSheet -- CTRL+SPACE will autocomplete that part, or I can select the available options from a dropdown list.
However- the Intellisense dropdown box and autocompletion won't work /appear for anything after the first full stop. For example I can't autocomplete the UsedRange property.
Is it possible to make the suggestions appear etc. past writing the first part?
回答1:
If you look at ActiveSheet in the Object Browser (press F2), you'll see that ActiveSheet is typed as Object. Therefore, Intellisense can't display any further properties specific to the Worksheet. The typing of Object makes sense, because the active sheet might be something other than a standard Excel worksheet -- e.g. a chart sheet or a dialog sheet.
Many global properties are strongly typed, e.g. ActiveWorkbook as Workbook; Intellisense will present the properties and methods just fine.
If you are certain that ActiveSheet when used in this code will always refer to a Worksheet, you could assign it to a Worksheet variable:
Dim wks As Worksheet
Set wks = ActiveSheet
Intellisense would then give you the appropriate properties and methods of the Worksheet object for the strongly-typed variable:
(Theoretically, the Excel object model could have typed ActiveSheet as something like Sheet, which would have all the common members of Worksheet, Chart and DialogSheet. I'm not sure why this wasn't done.)
来源:https://stackoverflow.com/questions/60387950/autocomplete-drop-down-box-for-arguments-past-the-first-full-stop