Skip to main content

Conas stop-faire a chruthú i mbileog oibre Excel?

Má tá stad-faire i do bhileog oibre, beidh a fhios agat an t-am chun post a chríochnú. Conas is féidir leat stad-faire a chruthú i mbileog le Cnaipe Tosaigh, Stop agus Athshocraigh mar a thaispeántar an scáileán seo a leanas? Má chliceálann tú an cnaipe Tosaigh, tosóidh sé am, má chliceálann tú an cnaipe Stop, stadfaidh sé am, agus féadann an cnaipe Athshocraigh cabhrú leat am a athshocrú. An t-alt seo, labhróidh mé faoi conas stad-faire simplí agus áisiúil a chruthú in Excel.

doc cruthaigh stad-faire 1

Cruthaigh stad-faire le trí chnaipe trí chód VBA a úsáid


Cruthaigh stad-faire le trí chnaipe trí chód VBA a úsáid

Chun stad-faire a chruthú le trí chnaipe, Tosaigh, Stop agus Athshocraigh, déan na céimeanna seo a leanas ceann ar cheann, le do thoil.

Ar dtús, cuir isteach trí chnaipe ordaithe.

1. Cliceáil Forbróir > Ionsáigh > Cnaipe Ordú, féach ar an scáileán:

doc cruthaigh stad-faire 2

2. Ansin tarraing an luch chun cnaipe a tharraingt, tar éis duit an cnaipe a chur isteach, is féidir leat fotheideal an chnaipe a athrú, cliceáil le do thoil Forbróir > Airíonna, I Airíonna dialóg, iontráil an fotheideal nua “Tòisich”Don chnaipe seo sa bhosca téacs in aice leis an Fotheideal, féach screenshots:

doc cruthaigh stad-faire 3 2 doc cruthaigh stad-faire 4

3. Déan an dá chéim thuas arís chun dhá chnaipe eile a chur isteach agus ceannteideal orthu mar “stad"Agus"athshocrú”, Féach an pictiúr:

doc cruthaigh stad-faire 5

4. Tar éis duit na cnaipí a chur isteach, ba cheart duit an modh dearaidh a fhágáil trí chliceáil Forbróir > Mód Dearaidh.

Ar an dara dul síos, cruthaigh cód VBA.

5. Agus ansin, cliceáil ar dheis ar an táb bileog oibre reatha, agus roghnaigh Féach an cód, sa popped amach Microsoft Visual Basic d’Fheidhmchláir fuinneog, cóipeáil agus greamaigh an cód seo a leanas isteach sa Cód Bileog:

Cód VBA: Cruthaigh stad-faire:

Public StopIt As Boolean
Public ResetIt As Boolean
Public LastTime
Private Sub CommandButton1_Click()
Dim StartTime, FinishTime, TotalTime, PauseTime
StopIt = False
ResetIt = False
If Range("C2") = 0 Then
  StartTime = Timer
  PauseTime = 0
  LastTime = 0
Else
  StartTime = 0
  PauseTime = Timer
End If
StartIt:
  DoEvents
  If StopIt = True Then
    LastTime = TotalTime
    Exit Sub
  Else
    FinishTime = Timer
    TotalTime = FinishTime - StartTime + LastTime - PauseTime
    TTime = TotalTime * 100
    HM = TTime Mod 100
    TTime = TTime \ 100
    hh = TTime \ 3600
    TTime = TTime Mod 3600
    MM = TTime \ 60
    SS = TTime Mod 60
    Range("C2").Value = Format(hh, "00") & ":" & Format(MM, "00") & ":" & Format(SS, "00") & "." & Format(HM, "00")
    If ResetIt = True Then
      Range("C2") = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
      LastTime = 0
      PauseTime = 0
      End
    End If
    GoTo StartIt
  End If
End Sub
Private Sub CommandButton2_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
  StopIt = True
End Sub
Private Sub CommandButton3_Click()
  Range("C2").Value = Format(0, "00") & ":" & Format(0, "00") & ":" & Format(0, "00") & "." & Format(0, "00")
  LastTime = 0
  ResetIt = True
End Sub

doc cruthaigh stad-faire 6

nótaí: Sa chód thuas, C2 an cill ina gcuirfear an t-am stad-faire isteach, agus an Cnaipe Ordú1, Cnaipe Ordú2, Cnaipe Ordú3 is iad ainmneacha na gcnaipe, is féidir leat ainm cruinn an chnaipe a fheiceáil ón Ainm Bosca, féach ar an scáileán:

doc cruthaigh stad-faire 7

Ar an tríú dul síos, formáidigh an chill ama stad-faire.

6. Ansin ba chóir duit an chill ama a fhormáidiú mar Téacs formáid, agus is féidir leat méid na cille, an cló, an clómhéid, an cúlra, srl a athrú de réir mar a theastaíonn uait, féach an scáileán:

doc cruthaigh stad-faire 8

7. Tar éis críochnú os cionn céimeanna, as seo amach, nuair a chliceálann tú Tòisich cnaipe, cuirfear tús leis an am anois, agus cliceáil stad cnaipe, stopfaidh sé am, an athshocrú athshocróidh an cnaipe an t-am, féach an scáileán:

doc cruthaigh stad-faire 9


Taispeántas: Cruthaigh stad-faire le trí chnaipe trí chód VBA a úsáid

Uirlisí Táirgiúlachta Oifige is Fearr

🤖 Kutools AI Aide: anailís sonraí a réabhlóidiú bunaithe ar: Forghníomhú Chliste   |  Gin Cód  |  Cruthaigh Foirmlí Saincheaptha  |  Anailís a dhéanamh ar Sonraí agus Cairteacha a Ghin  |  Feidhmeanna Kutools a agairt...
Gnéithe Coitianta: Faigh, Aibhsigh nó Aithnigh Dúblaigh   |  Scrios Sraitheanna Bána   |  Comhcheangail Colúin nó Cealla gan Sonraí a Chailleadh   |   Babhta gan Foirmle ...
Cuardaigh Super: Ilchritéir VLookup    VLookup Illuachanna  |   VLookup Trasna Ilbhileoga   |   Amharc doiléir ....
Liosta anuas Casta: Go tapa Cruthaigh Liosta Anuas   |  Liosta anuas Cleithiúnach   |  Liosta Buail Isteach Ilroghnacha ....
Bainisteoir Colún: Cuir Líon Sonrach Colún leis  |  Colúin Bog  |  Scoránaigh Stádas Infheictheachta na gColún Ceilte  |  Déan comparáid idir Raonta & Colúin ...
Gnéithe Réadmhaoin: Fócas Eangaí   |  Amharc Dearaidh   |   Barra Mór na Foirmle    Leabhar Oibre & Bainisteoir Bileog   |  Leabharlann Acmhainní (Uaththéacs)   |  Piocálaí Dáta   |  Comhcheangail Bileoga Oibre   |  Criptigh/Díchriptigh Cealla    Seol Ríomhphost trí Liosta   |  Scagaire Super   |   Scagaire Speisialta (scagaire trom/iodálach/stailc tríd...) ...
Barr 15 Uirlisí12 Téacs uirlisí (Cuir Téacs, Bain Carachtair,...)   |   50 + Cairt cineálacha (Cairt Gantt,...)   |   40+ Praiticiúil Foirmlí (Ríomh aois bunaithe ar lá breithe,...)   |   19 Insertion uirlisí (Cuir isteach Cód QR, Ionsáigh Pictiúr ón gCosán,...)   |   12 Tiontú uirlisí (Uimhreacha le Focail, Comhshó Airgeadra,...)   |   7 Cumaisc & Scoilt uirlisí (Sraitheanna Comhcheangail Casta, Cealla Scoilt,...)   |   ... agus eile

Supercharge Do Scileanna Excel le Kutools le haghaidh Excel, agus Éifeachtúlacht Taithí Cosúil Ná Roimhe. Kutools le haghaidh Excel Tairiscintí Níos mó ná 300 Ardghnéithe chun Táirgiúlacht a Treisiú agus Sábháil Am.  Cliceáil anseo chun an ghné is mó a theastaíonn uait a fháil ...

Tuairisc


Tugann Tab Oifige comhéadan Tabbed chuig Office, agus Déan Do Obair i bhfad Níos Éasca

  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
Comments (32)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
One has to paste the VBA code to the Sheet's VBA space, not to the Module!

=> I suggest correcting, in the article, the "copy and paste the following code into the Module" -> replace Module with Sheet's VBA field, or sth

Otherwise, perfect, thanks!
This comment was minimized by the moderator on the site
Hello, Florian,

Thanks for your comment, we have updated the content for this article.
Thanks again! 😀
This comment was minimized by the moderator on the site
i started. it works. but it doesn't work when i close and open the excel file again. what must i do?
This comment was minimized by the moderator on the site
Hello, mustafa zirek
After inputing the code, you should save the workbook as Excel Macro-Enabled Workbook format, and when you open the workbook next time, please click the Enable Content above the formula bar to activate the code.
Please have a try, hope it can help you!
This comment was minimized by the moderator on the site
Hi! Thank you for this, how do I make it so it populates time in subsequent cells, ex. start/stop time for cell C2, then a different start/stop time for cell c3, c4, c5 etc 
This comment was minimized by the moderator on the site
Bonjour, j'ai voulu intégrer ce chronomètre à une autre macro, déterminer le temps d'utilisation du fichier. La macro se lance mais bloque l'utilisation du fichier.Comment faire pour utiliser votre chronomètre en même temps que d'autres codes VBA?MerciHenry.
This comment was minimized by the moderator on the site
Is it possible to use a combobox or a dropdown selection to start and stop the clock
This comment was minimized by the moderator on the site
This is brilliant! Thanks, Chris H
This comment was minimized by the moderator on the site
Hello
Have followed the steps but cannot get a time to appear in the timer cell. I have copied the code but can i check1. That the line numbers are not needed or are they2. That I put the code into module 1 not sheet1 or This workbook3. Should there be a macro listed in the macro list after doing all this - mine doesn't.
Thanks
This comment was minimized by the moderator on the site
Hi, Janice,You should put the code into your active sheet module as step 5.
5. And then, right click the current worksheet tab, and choose View Code, in the popped out Microsoft Visual Basic for Applications window, please copy and paste the following code into the Module.

And you should change the button name to your own.
Note: In the above code, C2 is the cell where the stopwatch time will be inserted, and the CommandButton1, CommandButton2, CommandButton3 are the button names, you can view the exact button name from the Name Box.

Please check them, thank you!
This comment was minimized by the moderator on the site
Is it possible to get the counter to count only seconds?
So when it reaches 59 seconds, it continues with 60, 61, 62, 63 ....
This comment was minimized by the moderator on the site
is 'timer' a variable here? dont see its relevance in the code.
This comment was minimized by the moderator on the site
How about adding "+10s" & "2x Speed" feature in this code?
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations