免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
e800,国内最具活力的IT门户网站。【e800编译】此示例演示在Microsoft Excel 2010中如何利用DisplayFormat类对一定范围的数据设置条件格式。此代码段是Office 2010的101项VBA代码示例中的一部分。与其它示例一样,这些将可以直接写入您的代码中。每块示例代码包含约5至50行的代码,分别演示了一个独特的功能或功能集,在VBA或VB以及C中(在Visual Studio 2010中创建)。每个示例之中都会包含代码以及相应注释,这样您就可以直接运行获取预期的结果,或者是根据代码注释提示来调整环境,运行示例代码。Microsoft Office 2010提供了你所需要的工具来创建功能强大的应用程序。Microsoft Visual Basic Application(VBA)代码示例可以帮助你创建自己的应用程序,以执行特定功能或者以此为出发点实现更为复杂的功能。实例代码在Excel 2010中新建工作簿,将代码复制到Sheet1类模块,然后按F5全速运行程序。检查在Excel中的单元格的格式,然后检查代码运行结果。 Excel 2010Sub TestDisplayFormat() From the documentation: Actions such as changing the conditional formatting or table style of a range can cause what is displayed in the current user interface to be inconsistent with the values in the corresponding properties of the Range object. Use the properties of the DisplayFormat object to return the values as they are displayed in the current user interface. In Excel 2010, in a new workbook, copy all this code into the Sheet1 class module. Place the cursor in this procedure, and then press F5 to run the procedure full speed. Examine the formatting of the cells in Excel, and then examine the results of running the procedure in the Immediate window. This example places some simple data into Sheet1, and then applies conditional formatting. Then, it compares the values of various formatting properties of the range to the formatting properties of the Range.DisplayFormat object:Range(A1).Value = -20Range(A2).Value = 10Dim rng As RangeSet rng = Range(A1:A2) Set up the conditional formatting:rng.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess, Formula1:=0With rng.FormatConditions(1)With .Font.Bold = True.Italic = True.Color = vbRedEnd WithWith .Borders.LineStyle = xlContinuous.Weight = xlThinEnd WithWith .Interior.PatternColorIndex = xlAutomatic.Color = vbYellowEnd WithEnd With Now compare formatting information for the range, and what its actually displaying (using the DisplayFormat property). Clearly, without the DisplayFormat property, you have no way to find out the formatting that appears to the user. The DisplayFormat property is an instance of the DisplayFormat class and contains many different members. This code only investigates the properties that might have been changed by conditional formatting. A1 has had conditional formatting changes because its negative. A2 has not.CompareRangeAndDisplayFormat Range(A1)CompareRangeAndDisplayFormat Range(A2)End SubPrivate Sub CompareRangeAndDisplayFormat(rng As Range) Show off the differences in properties that have been changed by conditional formatting:Debug.PrintDebug.Print rng.Address & =Debug.Print Interior color has been modified for negative values. Therefore, note that for cells that arent changed by conditional formatting, the range values and the DisplayFormat values are the same. For those that have been altered by conditional formatting, theyre different. This code doesnt check out all the properties; it just works through enough to prove that the properties of the Range object may not match those of the Range.DisplayFormat object:Debug.Print rng.Interior.Color: & rng.Interior.ColorDebug.Print rng.DisplayFormat.Interior.Color: & rng.DisplayFormat.Interior.ColorDebug.PrintDebug.Print rng.Font.Color: & rng.Font.ColorDebug.Print rng.DisplayFormat.Font.Color: & rng.DisplayFormat.Font.ColorDebug.PrintDebug.Print rng.Font.Italic: & rng.Font.ItalicDebug.Print rng.DisplayFormat.Font.Italic: & rng.DisplayFormat.Font.ItalicDebug.PrintDebug.Print rng.Font.Color: & rng.Font.ColorDebug.Print rng.DisplayFormat.Font.Color: & rn
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024-2030年中国美容仪器设备行业市场深度分析及发展策略分析报告
- 出院随访总结分析
- GB/T 4074.3-2024绕组线试验方法第3部分:机械性能
- 2018-2024年中国汽车租赁市场运行动态监测及发展前景投资预测报告
- 2019-2025年中国高纯稀土行业市场调查研究及投资潜力预测报告
- 年产6000万米纳米化纤新型面料项目可行性研究报告
- 生产尾气提标改造项目可行性研究报告
- 三聚氰胺熔盐炉低氮改造项目可行性研究报告
- 毕业季营销策划方案(2篇)
- 2023年铌资金筹措计划书
- 两个细则培训课件
- 建国大业观后感课件
- 5.40.31火灾自动报警系统手动火灾报警按钮安装质量标准和检验方法(完)
- 物流配送服务合同模板
- HGT 6189.2-2023 石油和化工用软起动装置技术应用导则 第2部分:设计选型 (正式版)
- 教师布置及批改作业检查量化评价评分表
- 传染病护理学知识考核试题题库与答案
- 浙教版小学信息科技四上一单元试卷附有答案
- 医疗器械仓库物品包装与运输标准
- 信用管理的大数据应用与挖掘
- 抽水蓄能电站研究预测报告-中国抽水蓄能电站行业深度剖析研究与投资分析预测报告(2024-2028年)
评论
0/150
提交评论