欢迎来到天天文库
浏览记录
ID:12749008
大小:27.45 KB
页数:4页
时间:2018-07-18
《使用displayformat方法设置数据范围的格式》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、e800,国内最具活力的IT门户网站。http://www.e800.com.cn【e800编译】此示例演示在MicrosoftExcel2010中如何利用DisplayFormat类对一定范围的数据设置条件格式。此代码段是Office2010的101项VBA代码示例中的一部分。与其它示例一样,这些将可以直接写入您的代码中。每块示例代码包含约5至50行的代码,分别演示了一个独特的功能或功能集,在VBA或VB以及C#中(在VisualStudio2010中创建)。每个示例之中都会包含代码以及相应注
2、释,这样您就可以直接运行获取预期的结果,或者是根据代码注释提示来调整环境,运行示例代码。MicrosoftOffice2010提供了你所需要的工具来创建功能强大的应用程序。MicrosoftVisualBasicApplication(VBA)代码示例可以帮助你创建自己的应用程序,以执行特定功能或者以此为出发点实现更为复杂的功能。实例代码在Excel2010中新建工作簿,将代码复制到Sheet1类模块,然后按F5全速运行程序。检查在Excel中的单元格的格式,然后检查代码运行结果。'Excel2
3、010SubTestDisplayFormat()'Fromthedocumentation:'Actionssuchaschangingtheconditionalformattingor'tablestyleofarangecancausewhatisdisplayedin'thecurrentuserinterfacetobeinconsistentwiththe'valuesinthecorrespondingpropertiesoftheRangeobject.'Usetheprope
4、rtiesoftheDisplayFormatobjecttoreturn'thevaluesastheyaredisplayedinthecurrentuserinterface.'InExcel2010,inanewworkbook,copyallthiscodeinto'theSheet1classmodule.Placethecursorinthisprocedure,'andthenpressF5toruntheprocedurefullspeed.Examine'theformatt
5、ingofthecellsinExcel,andthenexamine'theresultsofrunningtheprocedureintheImmediatewindow.'ThisexampleplacessomesimpledataintoSheet1,ande800,国内最具活力的IT门户网站。http://www.e800.com.cn'thenappliesconditionalformatting.'Then,itcomparesthevaluesofvarious'format
6、tingpropertiesoftherangetothe'formattingpropertiesoftheRange.DisplayFormatobject:Range("A1").Value=-20Range("A2").Value=10DimrngAsRangeSetrng=Range("A1:A2")'Setuptheconditionalformatting:rng.FormatConditions.AddType:=xlCellValue,Operator:=xlLess,Form
7、ula1:="=0"Withrng.FormatConditions(1)With.Font.Bold=True.Italic=True.Color=vbRedEndWithWith.Borders.LineStyle=xlContinuous.Weight=xlThinEndWithWith.Interior.PatternColorIndex=xlAutomatic.Color=vbYellowe800,国内最具活力的IT门户网站。http://www.e800.com.cnEndWithE
8、ndWith'Nowcompareformattinginformationfortherange,and'whatit'sactuallydisplaying(usingtheDisplayFormatproperty).'Clearly,withouttheDisplayFormatproperty,youhavenoway'tofindouttheformattingthatappearstotheuser.The'DisplayFormatpropertyisaninstanceofth
此文档下载收益归作者所有