Sida Loo Abuuro VBA Macro Ama Script gudaha Excel

Microsoft Excel waxa ay u saamaxdaa isticmaalayaasha in ay si otomaatig ah u sameeyaan sifooyinka iyo amarada iyaga oo isticmaalaya macros iyo Visual Basic for Applications ( VBA ). VBA waa luqadda barnaamijka ee Excel(VBA is the programming language Excel) uu isticmaalo si uu u abuuro makros. Waxa kale oo ay fulin doontaa amarro toos ah oo ku salaysan shuruudo gaar ah.

Macros waa amarro taxane ah oo horay loo duubay. Waxay si toos ah u shaqeeyaan marka amar gaar ah la bixiyo. Haddii aad ku leedahay hawlo Microsoft Excel ah oo aad si isdaba joog ah u qabato, sida xisaabaadka, maaraynta mashruuca, ama mushahar bixinta, hab-raacyada habraacan ayaa kaa badbaadin kara waqti badan.

Marka la eego tab horumariyaha ee ku yaal (Developer)Ribbon ee Excel , isticmaalayaashu waxay duubi karaan gujisyada jiirka iyo furayaasha furayaasha (macro). Si kastaba ha ahaatee, hawlaha qaarkood waxay u baahan yihiin qoraal qoto dheer oo ka badan inta macros ay bixin karaan. Tani waa halka qorista VBA ay noqoto faa'iido weyn. Waxay u ogolaataa isticmaalayaasha inay abuuraan qoraallo aad u adag.

Maqaalkan, waxaan ku sharxi doonaa kuwa soo socda:

  • Awoodsiinta Qoraalada & Macros
  • Sida loo abuuro Macro gudaha Excel
  • Tusaalaha Gaarka ah ee Macro
  • Wax badan ka baro VBA
  • U samee badhanka(Button) si aad ugu bilowdo VBA(VBA)
  • Ku dar koodka(Add Code) si aad u siiso badhanka shaqaynta(Button Functionality)
  • Ma Shaqaysay?

Awoodsiinta Qoraalada & Macros(Enabling Scripts & Macros)

Kahor intaadan abuurin macros ama VBA scripts gudaha Excel , waa inaad awood u yeelataa tabka horumariyaha ee liiska (Developer )Ribbon . Tab-(Developer) sameeyaha looma hawlgelin si caadi ah. Si aad awood ugu yeelato:

  • Fur xaashida shaqada ee Excel.
  • Guji File > Options > Customize Ribbon.

  • Sax ku dheji sanduuqa ku xiga horumariyaha(Developer) .

  • Guji tab horumariyaha(Developer) ka menu -ka Ribbon .

  • Marka xigta, dhagsii Amniga Macro(Macro Security) oo sax sanduuqa ku xiga si aad awood ugu yeelatid makrosyada oo dhan (lama talinayo; koodka khatarta ah ayaa socon kara). (Enable all macros (not recommended; potentially dangerous code can run). )
  • Kadibna ku dhufo OK.

Sababta aan macros-ku si caadi ah loo damin oo ay ula iman waayaan digniin waa in ay yihiin kood kombuyuutar oo ka koobnaan kara malware.

Hubi(Make) in dukumeentigu ka yimid ilo lagu kalsoon yahay haddii aad ka shaqaynayso mashruuc la wadaago ee Excel iyo barnaamijyada kale ee Microsoft .

Marka aad dhammayso adeegsiga qoraalladaada iyo macroskaaga, dami dhammaan macros-yada si aad uga hortagto koodka xaasidnimada leh inuu faafiyo dukumentiyada kale.

Ku samee Macro gudaha Excel(Create a Macro in Excel)

Dhammaan ficillada aad ku sameyso Excel marka aad duubeyso makro ayaa lagu daraa. 

  • Laga soo bilaabo tab Developer, guji Record Macro .

  • Geli magaca Macro(Macro name) , Furaha Gaaban(Shortcut key) , iyo Sharaxaada. (Description. )Magacyada Macro(Macro) waa inay ku bilowdaan xaraf mana yeelan karaan meelo bannaan. Furaha gaaban waa in uu ahaado xaraf.

Go'aanso meesha aad rabto inaad ku kaydiso makro-ka xulashooyinka soo socda:

  • Buug-shaqeedka Macro-shaqsiyeedka(Personal Macro Workbook) : Tani waxay abuuri doontaa dukumeenti qarsoon oo Excel ah oo leh macros kaydsan si loogu isticmaalo dukumeenti kasta oo Excel ah.
  • Buug- hawleed Cusub(New Workbook) : Wuxuu abuuri doonaa dukumeenti cusub oo Excel si uu u kaydiyo macros-yada la abuuray.
  • Buug-hawleedkan(This Workbook) : Kani waxa kaliya oo lagu dabaqi doonaa dukumeentiga aad hadda tafatirayso.

Marka la sameeyo, dhagsii OK

  • Ku(Run) socodsii tallaabooyinka aad rabto inaad otomaatig u sameyso. Marka aad dhammayso, dhagsii Jooji Duubista(Stop Recording)
  • Markaad rabto inaad gasho macro-gaaga, isticmaal kiiboodhka gaaban ee aad siisay.

Tusaalaha Gaarka ah ee Macro(Specific Example Of a Macro)

Aan ku bilowno xaashiyaha fudud ee macaamiisha iyo inta lagu leeyahay. Waxaan ku bilaabi doonaa abuurista makro si loo qaabeeyo xaashida shaqada.

Aynu ka soo qaadno inaad go'aansatey in dhammaan xaashida faafinta ay isticmaalaan qaab ka duwan sida ku dhejinta magaca hore iyo kan dambe ee tiirar kala duwan. 

Waxaad gacanta ku bedeli kartaa tan. Ama waxaad samayn kartaa barnaamij adigoo isticmaalaya makro si aad si toos ah kuugu habayso si sax ah.

Diiwaangeli Macro(Record The Macro)

  • Guji Diiwaanka Macro(Record Macro) . Aan u wacno Format_Customer_Data oo guji OK
  • Si aan u helno qaabaynta aan rabno, waxaan u bedeli doonaa magaca tiirka koowaad Magaca koowaad(First Name)
  • Kadib geli tiir ku xigta A oo u wac Magaca Dambe(Last Name)
  • Calaamadee(Highlight) dhammaan magacyada tiirka koowaad (kuwaaso wali ku jira magaca hore iyo kan dambe), oo guji Xogta(Data) ka socota marinka ribbon.
  • Guji qoraalka ku socda tiirarka(Text to Columns) .

  • Sax ku xaddid(Delimited) > Xiga(Next ) > Kala saar meel bannaan(Separate by Space) > Xiga(Next ) > Dhammays(Finish) . Hoos ka eeg sawirka sawirka iyo sida magacyadii hore iyo kuwii dambe loo kala saaray habka sare.

  • Si aad u qaabayso goobta ku haboon ee hadhaaga(Balance Due) , muuji cadadka. Guji(Click) Guriga > Qaabka (Home )Shuruuda(Conditional Formatting) ah > Xeerarka Unugga Iftiimi(Highlight Cell Rules) > Ka Weyn(Greater Than ) > 0 .

Tani waxay muujin doontaa unugyada leh dheelitirnaanta. Waxaan ku darnay dhowr macaamiil oo aan lahayn dheelitirnaan sababtoo ah sii muujinta qaabaynta.  

  • Ku laabo Developer oo guji Jooji Duubista(Stop Recording) .

Codso Macro(Apply The Macro)

Aan ku bilowno xaashida asalka ah ka hor inta aanan duubin makro si aan u qaabaynno si sax ah. Guji (Click)Macros , dooro oo socodsii macro(Run) -ga aad hadda abuurtay.

Markaad socodsiiso makro, dhammaan qaabaynta waa laguu sameeyay. Macro-kan aan hadda abuurnay waxa lagu kaydiyaa Tifaftiraha Aasaasiga ah ee Visual(Visual Basic Editor) .

Isticmaalayaashu waxay ku socodsiin karaan macros siyaabo kala duwan. Akhri orod makro(Run a macro) si aad wax badan u barato.  

Wax badan ka baro VBA(Learn More About VBA)

Si aad u ogaato wax ku saabsan VBA, dhagsii Macro ka tab horumariyaha . (Developer)Hel mid aad samaysay oo guji Edit.

Koodhka aad ku aragto sanduuqa sare waa waxa la sameeyay markii aad duubtay macro-gaaga. 

Sidoo kale waa waxa aad socodsiin doonto marka aad rabto inaad u qaabayso xaashida lacag bixinta macaamiisha kale si la mid ah.

Samee badhan si aad ugu bilowdo VBA(Create a Button To Get Started With VBA)

Isticmaalka isla xaashida sare ee macaamiisha iyo inta lagu leeyahay, aynu abuurno beddelka lacagta.

  • Si aad u geliso curiye badhanka, u gudub tab  horumariyaha .(Developer )
  • Ka dooro batoonka ActiveX Command(ActiveX Command Button ) ka hoos u dhaca ku xiga Geli(Insert) qaybta Kontaroolada (Controls).

  • Jiid(Drag) badhanka meel kasta oo ka mid ah xaashida xaashida si aad si fudud u geli karto oo u beddelo hadhow haddii aad rabto.

  • Si aad ugu dhejiso koodka, midig-guji badhanka oo dooro Properties . Waxaan u haysan doonaa magaca(Name) sida CommandButton iyo qoraalka qoraalka(Caption ) si loo beddelo( Convert ) (tani waa qoraalka badhanka).

Ku dar koodka si aad u siiso badhanka shaqaynta(Add Code To Give The Button Functionality)

Codaynta VBA(VBA) kama dhacdo interface -ka Excel . Waxaa lagu sameeyaa deegaan gaar ah.  

  • Tag tab horumariyaha(Developer) oo hubi in Habka Nakhshadu(Design Mode) uu firfircoon yahay.

  • Si aad u gasho furaha badhanka aan hadda abuurnay, ku dhufo midigta oo dooro Koodhka Muuqaalka(View Code) .

  • Markaad eegto koodka sawirka hoose, ogaysii bilawga ( Private Sub ) iyo dhamaadka ( Dhammaadka Sub(End Sub) ) ee koodka ayaaba jira.

  • Koodhka hoose ayaa dhaqaajin doona habka beddelka lacagta.

ActiveCell.Value = (ActiveCell * 1.28)

Ujeedada aan ka leenahay qaybtan waa in aan beddelno lacagta ku jirta xaashida faafintayada. Qoraalka kore wuxuu ka tarjumayaa heerka sarrifka GBP ilaa USD . Qiimaha cusub ee unuggu waxa uu noqonayaa waxa hadda jira oo lagu dhufto 1.28.

Sawirka hoose wuxuu ku tusayaa sida koodku u ekaado daaqada VBA ka dib markaad geliso .

  • Tag File in navigation sare oo guji Xir oo ku soo celi Microsoft Excel(click on Close and Return to Microsoft Excel) si aad ugu noqoto interface ugu weyn ee Excel .

Ma Shaqaysay?(Did It Work?)

Kahor intaadan tijaabin koodhkaaga, waa inaad marka hore damisaa Qaabka Naqshadeynta(Design Mode) (guji dusha) si aad uga fogaato wax ka bedel kale oo aad siiso badhanka shaqayntiisa.

  • Ku qor(Type) nambar kasta xaashidaada ka dibna dhagsii badhanka Beddelka(Convert) . Haddii qiimaha lambarkaagu uu kordho ku dhawaad ​​rubuc-meel, wuu shaqeeyay.

Tusaalahan, waxaan dhigay lambarka 4 unug. Kadib markaad riixdo Beddel(Convert) , nambarku wuxuu isu beddelay 5.12. Maadaama 4 jeer 1.28 ay tahay 5.12, koodhka ayaa si sax ah loo fuliyay.

Hadda oo aad fahamtay sida loo abuuro makro ama qoraal gudaha Excel , waxaad u isticmaali kartaa si otomaatig ah ficillo badan oo Excel ah .



About the author

Waxaan u shaqeeyaa lataliye ahaan Microsoft. Waxaan ku takhasusay horumarinta barnaamijyada mobaylada ee aaladaha Apple iyo Android, waxaanan sidoo kale ka qayb qaataa horumarinta barnaamijyada Windows 7. Waayo-aragnimadayda taleefannada casriga ah iyo Windows 7 waxay iga dhigaysaa musharax ku habboon booskan.



Related posts