What is a VBA Macro in Excel? - Corporate Finance Institute

文章推薦指數: 80 %
投票人數:10人

VBA Macros use the Visual Basic Application in Excel to create custom user-generated functions and speed up manual tasks by creating ... Home›Resources›ExcelResources›Study›VBAMacros VBAMacros HowtosetupmacrosinVBA Writtenby CFITeam UpdatedFebruary9,2022 WhatareVBAMacrosinExcel? VBAMacrosusetheVisualBasicApplicationinExceltocreatecustomuser-generatedfunctionsandspeedupmanualtasksbycreatingautomatedprocesses. Additionally,VBAcanbeusedtoaccesstheWindowsApplicationProgrammingInterface(API). Oneofitsmainusesistochangeandcustomizetheuserinterfacebycreatingpersonalizedtoolbars,menus,dialogboxes,andforms. Tolearnmore,launchCFI’sExcelVBAcoursenow! Beforeyoucontinue,usetheformbelowtogetaccesstoourcomprehensiveVBAcheatsheetforanoverviewofkeycodesandmacros,terminology,andbestpracticesinExcelVBA. HowtoCreateExcelVBAMacros Inaseparatearticle,CFIdiscusseswhatVBAisandhowtoaccesstheVBAEditor.Asasummary,pressingAlt+F11inExcelopensuptheVBAwindowandallowstheusertobegincodingmacros. Tostartcoding,theuserwillhavetocreateaModulefile.Modulefilescontainagroupofmacros.Tocreateanewmodule,pressInsert>Module.Optionally,theusercannamethismoduleusingthepropertieswindowinthebottomleftcorneroftheeditor.Simplytypeinanewmodulenameandpressenter. HowtoNameExcelVBAMacros Tostartoff,themacromustbegivenauniquename.Thisnamecannotmatchothermacros,anditusuallycannotmatchthenameofotherproperties,functions,andtoolswithinExcel.Themacronameiswhattheuserwillusetocallthemacrointoaction. Todefineamacroname,theusermusttypeSubname()andpress“enter”inthecodingwindowoftheeditor.PressingenterwillautomaticallyfillthewindowwiththegeneralformatofanExcelmacro.Forexample,tonamethemacro“CFIMacro”,ausershouldtype“SubcfiMacro()”andpressenter.TheVBAEditorwillautomaticallyaddan“EndSub”lineafewlinesbelowthe“Sub”. Note:Thegeneralconventionfortypingnamesforanymacro,function,orvariableinVBAistouselowercaseifthereisonlyoneword,andtouseanuppercaseletteratthestartofeverynewword.VBAnamesgenerallycannotcontainspaces.SinceCFIMacroistwowords,thisshouldbewrittenascfiMacro.However,thesearejustbestpracticeguidelinesandneednotnecessarilybeadheredto. SubNameinVBA TheSubName()linetellstheeditorthestartofthemacrocode.TheEndSubdenotestheend.Iftheuserwantedto,heorshecouldcreateasecondnewmacrobystartinganewSubName()linebelowthefirstEndSub.TrythisoutandyoushouldnoticethatExcelwillautomaticallycreatealinebetweenthetwodifferentmacros. ThisisthebasicstructureofanExcelmacro.Thenextstep,beforejumpingintotheactualprocesscoding,istodefinethevariablestheuserisgoingtouseinthecode.Youmaybeinterestedinourfully-fledgedExcelVBAmacrocourse.Clickhere tolaunchthecoursenow! AdditionalResources ThankyouforreadingtheCFIintroductoryguidetoVBAmacrosinExcel.Tokeeplearningandadvancingyourcareer,checkouttheseadditionalCFIresources: ExcelShortcuts(PCandMac) AdvancedExcelFormulas ListofExcelFunctions FreeExcelCourse Sharethisarticle GetCertifiedfor
BusinessIntelligence(BIDA™) DevelopanalyticalsuperpowersbylearninghowtouseprogramminganddataanalyticstoolssuchasVBA,Python,Tableau,PowerBI,PowerQuery,andmore. LearnMore CorporateFinanceInstitute BacktoWebsite 0searchresultsfor‘’ Peoplealsosearchfor: excel Free freecourses accounting Balancesheet 2 DCF ExploreOurCertifications FinancialModeling&ValuationAnalyst(FMVA)® Learnmore CommercialBanking&CreditAnalyst(CBCA)™ Learnmore CapitalMarkets&SecuritiesAnalyst(CMSA)® Learnmore CertifiedBusinessIntelligence&DataAnalyst(BIDA)™ Learnmore Resources ExcelShortcutsPCMac ListofExcelShortcuts Excelshortcuts[citation... FreeFinancialModelingGuide ACompleteGuidetoFinancialModeling Thisresourceisdesignedtobethebestfreeguidetofinancialmodeling!Wewillbreakdownthemostimportant... SQLDataTypes WhatareSQLDataTypes? TheStructuredQueryLanguage(SQL)comprisesseveraldifferentdatatypesthatallowittostoredifferenttypesofinformation... StructuredQueryLanguage(SQL) WhatisStructuredQueryLanguage(SQL)? StructuredQueryLanguage(SQL)isaspecializedprogramminglanguagedesignedforinteractingwithadatabase.... SeeAllResources SeeAll PopularCourses Free! FMVA®-PrepCourses 3.5h ExcelFundamentals-FormulasforFinance FMVA®-Required 5.5h Buildinga3StatementFinancialModel FMVA®-Required 7.5h BusinessValuationModelingPartI FMVA®-Required 2.5h Scenario&SensitivityAnalysisinExcel FMVA®-Required 6h Dashboards&DataVisualization FMVA®-Electives 11h LeveragedBuyoutLBOModeling SeeAllCourses SeeAll RecentSearches Suggestions FreeCourses ExcelCourses FinancialModeling&ValuationAnalyst(FMVA)®



請為這篇文章評分?