搜索: 标题内容作者  
  首页VB.NET教程VB.NET国外译文
背景:
阅读新闻

简化ADO/Excel 对象模型开发的VBA控件库

[日期:2007-07-24]   来源:MSProject开源技术  作者:未知   [字体: ]
    新闻简介:[翻译]
Rafey著VBA Library To Simplify ADO/Excel Object Model Development
环境:VB,Windows, .NET,Win32, Visual Studio
        关 键 词:   vba  Excel  控件 
[翻译]
Rafey著VBA Library To Simplify ADO/Excel Object Model Development

环境vb,Windows, .NET,Win32, Visual Studio

EXCEL VBA Library


[介绍]
在VSTO发布之后,VBA开发基本上已经是过时的了。然而,为了支持Office 2000,开发人员依然需要一个简单的基于VBA的解决办法。使用Excel的VBA库,我们可以象数据表一样进行插入,更新和查询。当然还有不少的其它库简化Excel VBA开发人员的工作。

库列表

* ACell: 使用这个库获得当前的行列及单元地址
* AComboBox: 使用这个库简化ComboBox 下拉框和ListBox列表框的加载
* AConst: 不管你的项目多小,在一个地方定义常量是非常有帮助的
* ALog:使用这个库,在一个命名为LOG的Sheet上记录日志。对于后天运行的程序而言,这是非常有用的
* AMsgForm: 取代MsgBox,它可以让你的应用程序的消息弹出框统一起来
* AOptions: 使用这个库,在一个命名为Option的Sheet中,get/set终端用户的引用
* ARange: Use this library to obtain valid range string or range object from a given row, column.
* ASQL: 这个库可以把Excel的Sheet当作数据库的Table来操作。该库对Excel Sheet的操作简化成INSERT, UPDATE和 SELECT
* AStr: 这个库用于字符串操作和格式化
* ATable: 这个库可以把Excel的Sheet当作数据库的Table,确保Sheet中第一行包含列名。它可以简化基于Sheet的任务

[代码使用]

1. 创建一个Excel Sheet
2. 按Alt+F11打开VBA编辑器
3. 拖拽所有的VBA库模型到工作簿中
4. 在Sheet上放置Button,并给每一个按钮赋宏

Code:
Sub Button1_Click()
    AMsgForm.Show "Use ALog library to write information in Log. _
                    A info Log is written."
    ALog.WriteErr "Use ALog library to write information in Log"

    AMsgForm.Show "Use ALog library to write errors in Log. _
                    An error Log is written."
    ALog.WriteInfo "Use ALog library to write errors in Log"
End Sub

Sub Button3_Click()
    AMsgForm.Show "You could have consistent messages with _
                        AMsgForm library"

    AMsgForm.ShowErr "& Errors. This is an error message"
End Sub

Sub Button5_Click()
    AMsgForm.Show "Use AOption library to get/set user preferences."

    AMsgForm.Show AOptions.StrGet(OptionE.Option1, "Not found")
End Sub

Sub Button7_Click()
    Dim rs

    AMsgForm.Show "Use ASQL library to SELECT, INSERT, UPDATE Excel sheet. _
     Now count of cities will be selected in City sheet."

    Set rs = ASQL.Run("City")

    AMsgForm.Show rs.RecordCount
End Sub

Sub Button8_Click()
    AMsgForm.Show "Use AStr  for string manipulation and formatting."

    AMsgForm.Show AStr.Quote("Quote a string in VBA always ends up _
    in dirty and less maintainable code. But its easy with AStr.Quote")

    AMsgForm.Show AStr.Bracket("To bracket use AStr.Bracket")
End Sub

If you believe an article violates your rights or the rights of others, please contact us.

收藏 推荐 打印 | 录入:admin | 阅读:
相关新闻      
友情链接
本文评论   [发表评论] 全部评论 (0)
赞助商广告
热门评论