Importing Macro into Excel 2010 

advertisement
Importing Macro into Excel 2010 Touseacustommacroprovidedinthisclassyoumustmakesurethatthesecurityisset
accordingly.Tocheckand/orchangeyoursecuritylevelclickontheFile tab, Options;then
selectTrust Center,clickTrust Center Settings…;finallyselectMacro Settings.(Seethe
followingscreenshots.)
J.L.Jechura
‐1‐
March23,2013
Therearemultipleoptionsforhandlingmacrosinaspreadsheet.Theoneshownabove,
Disable all macros with notification,givesthemostflexibilitybetweenbeingabletorun
macroswithsecurityofnotallowingunexpectedmacrostorunautomatically.Whenthis
optionischosen,youwillhavetoexplicitlygivepermissiontorunaspreadsheetcontaining
amacro.Afteropeningaspreadsheetwithoneormacrosyouwillgetasecuritywarning
(seethefollowingscreenshot).SelectingEnable Contentwillallowyouthemacrostorun.
Excel2007introduced&Excel2010continuesanotheroptiontocontrolwhatmacroscan
startautomatically,thatofTrustedLocations.TheselocationscanalsobesetintheTrust
Center.ThislocationcanbereachedbyclickingontheFile tab, Options;thenselectTrust Center,clickTrust Center Settings…;finallyselectTrusted Locations.Severallocationsareset
bydefaultwhenExcel2010isinstalled.Otherscanbeadded(suchas"C:\Users\Daddy‐
O\Documents\Refining&EnergyTech\CommonClassFiles"inthefollowingscreenshot).
TheuseofTrustedLocationsshouldbeusedwithcare;onemightwanttoopenup
J.L.Jechura
‐2‐
March23,2013
spreadsheetsreceivedfromothersinanon‐trustedlocationfirsttoensurethatmalicious
codehasnotbeenattachedtothespreadsheet.
Theactualprocesstoimportthecodehasmultiplesteps:
1. OpentheMacroEditor.ClickontheDevelopertab&Visual Basicbutton.(Ashortcut
todothisispressAlt‐F11.)
2. Onceinthemacroeditor,ensurethatthatyourcurrentspreadsheetisactive.Inthe
ProjectExplorerpaneensurethatyourspreadsheetofinterestishighlighted.(Ifthe
ProjectExplorerpaneisnotvisible,clickonView,Project Explorerorpressthe
shortcutkeycombination,Ctrl+R.)
J.L.Jechura
‐3‐
March23,2013
3. Importthemacroasa.BASfile.ClickonFile,Import File….WhentheFile Open
dialogueboxopens,findthefileofinterest,highlight,andclickOpen.
J.L.Jechura
‐4‐
March23,2013
4. Oncethefilehasbeenopenedyoushouldbeabletodouble‐clickontheModule’s
nameinthePropertieswindow&seethecodeintheeditorwindow.
J.L.Jechura
‐5‐
March23,2013
5. OncebackinExcelthepublicfunctionsintheBasicmodulearenowavailableunder
theUserDefinedcategorywheninsertingafunction(eitherbypressingInsert FunctionintheFormulastabortheMore Functions…intheAutoSumbutton).
J.L.Jechura
‐6‐
March23,2013
J.L.Jechura
‐7‐
March23,2013
Download