您好,欢迎来到中国最大的生活服务网站![登录][注册]
版主:Mniwtian   副版主:
点击查看所有副版主

ationusernam

youmayhaveaSubprocedurethatbinesvariouspartsofaworkbookintoaconcisereport

 

FunctionproceduresAfunctionisasetofinstructionsthatreturnsasinglevalueoran

arrayYoucanuseFunctionproceduresinwiorksehepetformulas

 

DeclarationsAdeclarationisinformationaboutavariablethatyouprovidetoVBAFor

exampleyoucandeclarethedatatypeforvariablesthatyouplantouseDeclarationsgoat

thetopofthemodule

 

AsingleVBAmodulecanstoreanynumberofproceduresanddeclarations

 

NoteThisbookfocusesexclusivelyonFunctionprocedureswhicharetheonlytypeof

procedurethatyoucanuseinwiorksehepetformulas

 

 

EnteringVBACode

ThissectiondescribesthevariouswaysofenteringVBAcodeinacodewindowForFunction

proceduresthecodewindowwillalwaysbeaVBAmoduleYoucanaddcodetoaVBAmodulein

threeways

 

Useyourkeyboardtotypeit

 

UsetheExcelmacrorecorderfeaturetorecordyouractionsandconvertthemintoVBAcode

 

Copythecodefromanothermoduleandpasteitintothemodulethatyouareworkingon

 

ENTERINGCODEMANUALLY

SometimesthemostdirectrouteisthebestoneTypethecodebyusingyourkeyboard

EnteringandeditingtextinaVBAmoduleworksjustasyouexpectYoucanselecttextand

copyitorcutandpasteittoanotherlocation

 

UsetheTabkeytoindentthelinesthatlogicallybelongtogetherforexamplethe

conditionalstatementsbetweenanIfandanEndIfstatementIndentationisnotnecessary

butitmakesthecodeeasiertoread

 

AsingleinstructioninVBAcanbeaslongasyouwantForthesakeofreadabilityhowever

youmaywanttobreakalengthyinstructionintotwoormorelinesTodosoendtheline

withaspacefollowedbyanunderscorecharacterandthenpressEnterandcontinuethe

instructiononthefollowinglineThefollowingcodeforexampleisasinglestatement

splitoverthreelines

 

IfIsNumericMyCellThen

Result="Number"Else

Result="NonNumber"

 

NoticethatIindentedthelasttwolinesofthisstatementDoingthisisoptionalbutit

helpstoclarifythefactthatthesethreelinesmakeupasinglestatement

 

AfteryouenteraninstructiontheVBEditorperformsthefollowingactionstoimprove

readability

 

ItinsertsspacesbetweenoperatorsIfyouenterAns=12withoutanyspacesforexample

VBAconvertsitto

 

Ans=12

 

TheVBEditoradjuststhecaseofthelettersforkeywordspropertiesandmethodsIfyou

enterthefollowingtext

 

user=applice

 

VBAconvertsitto

 

user=ApplicationUserName

 

BecausevariablenamesarenotcasesensitivetheVBEditoradjuststhenamesofall

variableswiththesameletterssothattheircasematchesthecaseoflettersthatyoumost

recentlytypedForexampleifyoufirstspecifyavariableasmyvaluealllowercaseand

 

用户名: 请您登录后再发帖 
标 题: 标题请勿超过30个字
内 容:
 
  请阅读我们的[服务条款]
Copyright © 2009 Yahoo.com.cn 版权所有 不得转载 | 使用须知 | 著作权声明 | 京ICP证000022号 | 国家药监局(京)-经营性-2004-0039
全球阿里巴巴 - 阿里巴巴网络:中国站 国际站 日文站 | 淘宝站 | 支付宝 | 中国雅虎 | 口碑网 | 阿里软件 | 阿里妈妈