Sida xaashida Excel loogu koobi karo VBA

  • La Wadaag Tan
Michael Brown

Tababarku wuxuu bixiyaa ururin macros ah oo lagu koobi karo xaashida Excel: koobbi oo dib u magacow ku salaysan qiimaha unugga, nuqul ka samee xaashiyo badan, nuqul ka mid ah xaashi shaqo oo firfircoon fayl kale adigoon furin, iyo in ka badan. <3        Duubista xaashiyo badan oo dhawr jeer ah waa caajis iyo waqti. Boggaan, waxaad ka heli doontaa muggeed macros oo faa'iido leh si otomaatig ah hawshan

    >

Excel VBA si loo koobiyo xaashida buug-shaqeedka cusub

>Macro-kan ugu fudud ee hal-line ah ayaa sameeya. sida saxda ah waxa magaceedu soo jeedinayo - koobiyaya xaashida firfircoon buuga shaqada cusub.Public Sub CopySheetToNewWorkbook() activeSheet. Nuqul Dhammaadka Sub

Nuqul dhawr xaashi oo Excel leh VBA

Haddii aad jeclaan lahayd inaad koobbi dhowr xaashiyood oo ka mid ah buuga shaqada ee firfircoon una beddel mid cusub, dooro dhammaan xaashida shaqada ee xiisaha leh oo socodsii makrokan:

Shaqo-hoosaadka Dadweynaha ee NuqulladaXulashada Xaashiyaha 7>

Iyadoo ay ku xiran tahay meesha aad rabto inaad geliso xaashida la koobiyay, adeegso mid ka mid ah makrosyada soo socda.

>Koobi xaashida bilowga buug kale Dhammaan xaashiyaha kale ee ku jira faylka loo socdo, Book1ee tusaalahan. Si aad u nuqul ka sameyso fayl kale, ku beddel "Book1.xlsx" magaca buuxa ee buug-shaqeedka aad beegsaneyso.Public SubCopySheetToBeginningAnotherWorkbook() activeSheet. Nuqul ka hor:=Buuga shaqada( "Book1.xlsx") koobiga dhigaya dhamaadka Book1. Mar labaad, fadlan xasuusnoow inaad ku badasho "Book1.xlsx" magaca buuga shaqada aad u socoto.Buuga-hoosaadka dadweynaha ") Xaashiyaha shaqada.Tirinta) Dhammaadka Sub

Xusuusin. Si uu macrosku u shaqeeyo, buuga shaqada ee la beegsanayaa waa in lagu kaydiyaa dariiqaaga adag ama shabkada Waxaad samayn kartaa UserForm (oo lagu magacaabo UserForm1 ) oo wata ListBox kontorool ( lagu magacaabo ListBox1 ) iyo laba badhan:

>

> >>

Marka ku xigta, laba jeer guji foomka oo ku dheji summada hoose ee daaqadda Code:

Buugga-Shaqaynta Dadweynaha ee loo xushay Sida Xadhkaha Isticmaalaha-hoosaadka Gaarka ahForm_Initialize() SelectedWorkbook = "" ListBox1.Clear for wbk kasta gudaha Codsiga.Buuga Shaqada ListBox1.AddItem (wbk.Name) Dhamaadka Xiga Hoosaadka Gaarka ah CommandButton1_guji () Haddii ListBox1.ListIndex & gt; -1 Markaas SelectedWorkbook = ListBox1.List(ListBox1.ListIndex) Dhammaadka Haddi Me.Qari Dhamaadka Sub Private Sub CommandButton2_Click() SelectedWorkbook = "" Me.Qari Dhamaadka Sub

Iyadoo uu jiro Form-ka isticmaalaha, waxaad isticmaali kartaa mid ka mid ah kuwan soo socda macros si loo koobiyoxaashida firfircoon ee ku socota buuga shaqada ee doorashadaada " ) Kadibna activeSheet.Copy Kahor:=Buuga shaqada(UserForm1.SelectedWorkbook) .Sheets(1) Waxay dhamaanaysaa haddi la soo dejiyo UserForm1 Dhammaadka Sub

Koobi ka bixi ilaa dhammaadka buuga shaqada ee la doortay :

Pubscribe CopySheetToEndAnotherWorkbook() Load UserForm1 UserForm1.Show if (UserForm1.SelectedWorkbook "" ) Kadibna activeSheet.Koobi ka dib:=Buugga shaqada ( _ UserForm1.SelectedWorkbook) .Sheets Dhammaadka Sub

Marka lagu shaqeeyo Excel, makro ayaa ku tusi doona liiska dhammaan buugaagta shaqada ee hadda la furay. Waxaad doorataa midka loo baahan yahay oo guji OK:

> > >Excel macro si aad u nuqul ka sameyso oo dib u magacowdo

Marka aad nuqul ka sameysato Excel, nuqulka waxaa la siinayaa magaca qaabka caadiga ah sida Sheet1 (2) . Macros-kan soo socdaa waxa ay kaa badbaadin karaan dhibka ah in aad gacanta ku badasho magaca caadiga ah.

Koodhkani waxa uu nuqul ka dhigayaa xaashida shaqada ee firfircoon, waxa uu koobiga u magacaabayaa "Sheetka Imtixaanka" (waxaad xor u tahay in aad ku bedesho magac kale oo aad jeceshahay) , oo dhig xaashida la naqilay dhamaadka buuga shaqada ee hadda jira"Sheetka Imtixaanka" Dhammaadka Sub

Si loogu ogolaado isticmaaluhu inuu sheego magaca xaashida la nuquliyay , isticmaal summadan:

Nuqul-hoosaadka Dadweynaha&Rename() Magaca cusub ka dhig sida Xadhkaha Qaladka Dib-u-soo-celinta Magaca cusub = InputBox(" Geli magaca xaashida shaqada ee la koobiyeeyay") Haddii Magaca cusub "" Kadib firfircooni Sheet. Nuqul ka dib:= Xaashiyaha shaqada(Waraaqaha. Tirinta) Cilada ku jirta Dib u bilaw Sheetka firfircoon ee Xiga wuxuu soo bandhigayaa sanduuqa wax gelinta ee soo socda, kaas oo aad ku qorto magaca la rabo oo taabo OK: > >>Excel macro si aad nuqul uga sameyso xaashida oo aad dib ugu magacowdo iyadoo lagu saleynayo qiimaha unugga

In xaaladaha qaarkood, waxaa laga yaabaa inay ku habboon tahay in la magacaabo nuqul leh qiime unug gaar ah, tusaale ahaan, madaxa tiirka. Taas awgeed, waxaad si fudud u qaadanaysaa koodhka sare oo aad si toos ah u gelisaa qiimaha unugga hadda la doortay sanduuqa gelinta si toos ah. Sida tusaalihii hore, nuqulka waxaa la dhigayaa dhamaadka buuga shaqada ee firfircoon.

Qaybta ugu dhibka badan waxay tahay in isticmaalayaashaadu ay had iyo jeer doortaan unugga saxda ah ka hor intaysan socon. macro :)

Nuqul ka mid ah Dadweynaha Nuqul ka dib: = Xaashiyaha shaqada(Waraaqaha. Tirinta) Cilad ku socota Dib u bilaw ActiveSheet.Name = Magaca Cusub Dhammaadka Hadii Uu Dhamaado Suber

Beddel ahaan, waxaad kartaa hardcode ciwaankaunugga oo ay tahay in koobiga lagu magacaabo, unugga A1 ee koodka hoose. Si aad u magacawdo xaashida shaqada ee la koobiyay ee ku salaysan unug kale, ku beddel A1 tixraac unug ku habboon.

Nuqul ka mid ah nuqul ka mid ah dadweynaha ( "A1") .Qiimaha "" Kadibna Khaladku Dib u bilaabo Xiga ActiveSheet.Name = wks.Range("A1") 0>Makrokan waxa uu koobiyayaa xaashida firfircoon ilaa dhamaadka buuga shaqada ee xidhan. Magaca buug-shaqeedka kale laguma qeexin koodka - makro wuxuu furi doonaa daaqadda caadiga ah ee Windows Explorer wuxuuna kuu oggolaanayaa inaad doorato fayl kasta oo aad u socoto:>>>>>> 3>> Ka dib markaad doorato faylka oo dhagsii furan, makroku wuxuu koobi doonaa xaashida firfircoon wuxuuna si toos ah u xidhayaa buuga shaqada ee la beegsanayo Files (*.xlsx), *.xlsx" ) Haddii fileName Been ah ka dibna Application.ScreenUpdating = Been Set currentSheet = Application.activeSheet Set closebook = Buugaga shaqada. Fur (fileName) xaashida hadda jirta. Nuqul ka dib:=Book-xiran Xir ( Run ) Codsigafuritaanka

Macro-kan waxa uu awood kuu siinayaa in aad nuqul ka sameysato xaashi shaqo oo ka mid ah fayl kale oo Excel ah adiga oo aan furin. Xaashida la naqilay waxa la gelin doonaa dhamaadka buuga shaqada ee hadda.

>Xusuuso uun inaad samayso laba beddel oo koodka:>
    >C:\ UsersXXX\Documents\ Target_Book.xlsx waa in loo badalaa dariiqa dhabta ah iyo magaca buuga shaqada ee aad rabto in aad xaashi ka guuriso.
  • Sheet1 waa in lagu badalaa magaca xaashida aad rabto in aad nuqul ka sameyso
Nuqul-hoosaadka Dadweynaha ee laga soo qaatayClosedWorkbook Fur ("C:\ Users\XXX\Documents\Target_Book.xlsx") sourceBook.Sheets( "Sheet1").Koobi ka dib:=Buug-shaqeedkan.Sheets(ThisWorkbook.Sheets.Count) sourceBook. Xir Application Tan waxaa si fudud loogu samayn karaa makro-kan soo socda.Public Sub DuplicateSheetMultipleTimes() Dim n Sida Isku-xidhka Qaladka Dib u Bilaabashada Next n = InputBox("Immisa nuqul oo xaashida firfircoon ayaad rabtaa inaad samayso?") Haddii n > = 1 Kadibna nambarada = 1 To n activeSheet.Koobi ka dib:=ActiveWorkbookaad rabto in aad samayso, oo dhagsii OK:

Sida xaashida Excel loogu koobi karo VBA

Si aad u koobiyayso xaashi gudaha Excel ah Mid ka mid ah macro-yada sare, waxaad geli kartaa code-ka VBA-ga buuggaaga ama waxaad ka maamuli kartaa makro-buug-shaqeedka tusaalaha

Sida makro loogu daro buuggaaga shaqada

Si aad u geliso kood ku qor buuggaaga shaqada, samee tillaabooyinkan:

  1. Fur xaashida shaqada ee aad rabto inaad nuqul ka sameyso
  2. >Riix Alt + F11 si aad u furto Visual Basic Editor.
  3. Daar Shaxda bidix, midigta guji Buugga-Shaqada , ka dibna dhagsii Insert > Module .
  4. >>Ku dheji koodka daaqadda Code.
  5. Riix F5 si aad u socodsiiso makro
  6. >>>>
> Si aad u hesho tilmaamo tallaabo-tallaabo ah oo faahfaahsan, fadlan eeg Sida loo geliyo code VBA gudaha Excel>Sida loo ordo makro ka buuga shaqada ee muunad

Beddelkeeda, waxaad kala soo bixi kartaa buuga shaqada ee tusaalaha ah Nuplicate Sheets Excel oo aad halkaa ka socodsiiso koodka

> CopySheetToNewWorkbook- koobiyaya cu kirayso xaashida shaqada buugaag shaqo oo cusub ilaa bilawga buug kale oo shaqo.

CopySheetToEndAnotherWorkbook - koobiyaya xaashida firfircoon ilaa dhamaadka faylka kale ee Excel.

>CopySheetAndRename- nuqul ka dhigayaa kan hadda xaashida,dib u magcaabaa sida uu cayimay isticmaaluhu,oo koobiga ku dhejiyaa dhamaan xaashida kale ee ku jira buuga shaqada ee hadda.

CopySheetAndRenamePdefined - waxa uu nuqul ka dhigaa xaashida firfircoon, waxa uu siinayaa magac adag koobiga oo dhigaya dhammaadka buug-shaqeedka hadda jira

CopySheetAndRenameByCell - waxay samaysaa nuqul ka mid ah xaashida firfircoon oo dib u magacawday iyada oo ku saleysan qiimaha unugyada la doortay.

CopySheetAndRenameByCell2 - nuqul ka sameysaa xaashida firfircoon oo magaceedii iyadoo ku saleysan ciwaanka unugga adag.

CopySheetToClosedWorkbook - waxay kuu ogolaaneysaa inaad nuqul ka sameyso xaashida shaqada ee xiran.

CopySheetFromClosedWorkbook - waxa ay awood kuu siinaysaa in aad xaashi ka koobbi karto fayl kale oo Excel ah adiga oo aan furin ku orod makro ee Excel kaaga, kaliya samee sidan soo socota:

>
    >
  1. Fur buuga shaqada ee la soo dejiyay oo awood u yeel waxa ku jira haddii lagu weydiiyo.
  2. Fur buug-shaqeedkaaga oo u gudub xaashida aad rabto nuqul.
  3. <1 7> Xaashiyaha shaqada, taabo Alt + F8, dooro macro of interest, oo guji Run . > 21>

    > >

    Taasi waa sida aad u koobi karto xaashi ku taal Excel oo leh VBA. Waxaan kaaga mahadcelinayaa inaad akhriday waxaana rajeynayaa inaan kugu arko blog-keena toddobaadka soo socda!

Michael Brown waa xamaasad tignoolajiyada u heellan oo xiise u leh fududaynta hababka adag iyadoo la adeegsanayo aaladaha software. In ka badan toban sano oo waayo-aragnimo ah oo ku saabsan warshadaha teknoolajiyada, wuxuu ku horumariyay xirfadihiisa Microsoft Excel iyo Outlook, iyo sidoo kale Google Sheets iyo Docs. Blog-ga Michael wuxuu u heellan yahay inuu la wadaago aqoontiisa iyo khibradiisa dadka kale, isagoo siinaya tabo-fudud oo la raaco iyo casharro lagu horumarinayo wax soo saarka iyo hufnaanta. Haddii aad tahay xirfadle khibrad leh ama bilow ah, Michael's blog wuxuu bixiyaa fikrado qiimo leh iyo talooyin wax ku ool ah si aad uga faa'iidaysato qalabkan software-ka ah ee muhiimka ah.