使用 Excel 状态栏会容易得多:
Application.StatusBar = "向用户显示进度...";
对于 Windows 和任务栏进度条,您需要下载
Windows 7 任务栏:开发人员资源。
您需要打开示例解决方案,右键单击 Windows7.DesktopIntegration 项目 > 属性 > 构建 > 勾选注册 COM。
通过在开发期间检查 IDE 中的“Register for COM interop”选项,IDE 将在目标程序集上调用 regasm 以及 /codebase 选项。
这将导致 regasm.exe 为从您的程序集中导出的 COM 可见类添加以下注册表项:
HKEY_CLASSES_ROOT\CLSID{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}\InprocServer32\CodeBase=
这将使 CLR 能够按照程序集的路径定位您的程序集。如果没有代码库路径,CLR 将不得不使用标准搜索算法来定位您的程序集(及其依赖项)。
下一步构建解决方案 > 转到 Windows7.DesktopIntegration 项目的 bin 文件夹并将 Windows7.DesktopIntegration.DLL 和 Windows7.DesktopIntegration.TLB 复制到 System32 文件夹或更好地注册到 GAC。
一种帮助 CLR 定位所需程序集的相关技术是将所有程序集(及其依赖项)复制到与客户端应用程序本身相同的文件夹中。但是,您的客户端应用程序将是 Excel。这意味着您必须将程序集复制到与 Excel 应用程序相同的文件夹中(这不是一个好主意)。
一旦您能够实例化 Windows7.DesktopIntegration DLL,您应该能够调用该Windows7Taskbar.SetProgressValue
方法,例如 VBA 代码:
Set Windows7Taskbar = CreateObject("Windows7.DesktopIntegration")
Windows7Taskbar.SetProgressState(form.Handle, Windows7Taskbar.ThumbnailProgressState.Normal)
Windows7Taskbar.SetProgressValue(form.Handle, progress, maximum)