检测VBA中的Excel滚动 [英] Detecting Excel scroll in VBA

查看:369
本文介绍了检测VBA中的Excel滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过Pearson先生的 this ,表示excel对象模型不允许检测用户何时滚动,为了这样做,我们需要安装一些第三方的DLL,等等。



在Excel 2010中是否仍然如此?宏记录器似乎检测到滚动并将滚动位置打印到子程序中,当您滚动页面时(实际上您可以看到它实时执行此操作,如果您在滚动时显示该模块)...肯定有必要如果宏记录器在没有安装其他dll的情况下执行此操作,可以做一个方法?



由宏记录器生成的示例代码:

  ActiveWindow.ScrollRow = 16 
ActiveWindow.ScrollRow = 17
ActiveWindow.ScrollRow = 18
ActiveWindow.ScrollRow = 19


解决方案

Excel 2010中是否仍然如此? 为属性分配值或调用方法事件的挂起或收听截然不同。为了访问Excel应用程序的任何事件方法属性或其子对象,它们必须由VBA环境本质上暴露或通过使用Windows API。


I read this by Mr Pearson saying that the excel object model doesn't allow detecting when the user scrolls and that in order to do so, we'll need to install some third party dlls, etc...

Is this still true in Excel 2010? The macro recorder seems to detect scrolling and prints the scrolling location to the subroutine as you scroll around the sheet (in fact you can see it doing this in real-time if you have the module visible while you scroll)... Surely there must be a way to do this if the macro recorder is doing it without installing other dlls?

Example code generated by macro recorder:

ActiveWindow.ScrollRow = 16
ActiveWindow.ScrollRow = 17
ActiveWindow.ScrollRow = 18
ActiveWindow.ScrollRow = 19

解决方案

Is this still true in Excel 2010? Yes. Listening to or handling Events for window scrolling is not intrinsic to the VBA environment within Excel 2010.

Assigning a value to a Property or invoking a Method are quite different from "hooking" or "listening" for an Event. In order to access any Event, Method, or Property of the Excel application or its child objects they must be exposed intrinsically by the VBA environment or through the use of Windows APIs.

这篇关于检测VBA中的Excel滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆