Autocomplete / drop down box for arguments past the first full stop

自闭症网瘾萝莉.ら 提交于 2021-02-05 07:46:15

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!