



免费预览已结束,剩余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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年医院行政岗笔试考试题及答案
- Unit 5 Music说课稿-2025-2026学年高中英语人教新课标必修二-人教新课标2004
- 2025年3月茶艺师中级复习题与答案
- 2025届广东省云浮市云城区高三年级上册起调研模拟测试(一)历史试题(解析版)
- 2025年能源工程考试题目及答案
- 2025年高考上海物理试题+解析
- 小班幼师演讲题目及答案
- 2025汽车租赁合同范本示范
- 常州初三数学考试卷子及答案
- 2025房产交易买卖合同模板
- 2025-2026年秋季第一学期学校“蒲公英”广播稿(22周):第1周 从烽火岁月里“穿越”来的青春答案
- 2025下半年系统集成项目管理师考试真题及答案
- 急性结石型胆囊炎
- 无菌物品有效期课件
- 新媒体礼仪知识培训总结
- 2025 年小升初成都市初一新生分班考试语文试卷(带答案解析)-(部编版)
- 人教版七年级上册数学教学计划
- 护理事业十五五发展规划(2026-2030年)
- 2025云南昆明巫家坝建设发展有限责任公司招聘23人笔试备考试题及答案解析
- 重庆市七校联盟2024-2025学年高一下学期期末考试物理试卷(含解析)
- 2024年河北科技师范学院招聘真题
评论
0/150
提交评论