Johniny

KontrolaASpustenie

Mar 7th, 2020
527
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim insertedValue As String 'je mimo Sub aby bola globalna (bola rovnaka napriec vsetkymi Sub v tomto module) + lahsie sa hladaju
  2. Dim answer As Integer
  3. Dim hintLatestColumn As String
  4. 'https://support.microsoft.com/en-us/help/141693/scope-of-variables-in-visual-basic-for-applications
  5. 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/static-statement
  6.  
  7. Sub multipleIfs()
  8. 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/sub-statement
  9.  
  10. hintLatestColumn = Worksheets("Pharmap").Range("J4")
  11. 'moze byt uzitocne urobit automaticke najdenie najnovsieho stlpca pomocou SEARCH ale postaci i takto natvrdo ak sa nebude menit tvar pivotky
  12.  
  13. insertedValue = Application.InputBox("Napis nazev novehou sloupce:" & bnNewLine, "Nazev noveho sloupce", hintLatestColumn, Null, Null, Null, Null, 1 + 2)
  14. 'https://docs.microsoft.com/en-gb/office/vba/api/excel.application.inputbox
  15.  
  16. If Not ((insertedValue = "") Or (insertedValue = False)) Then
  17. 'https://docs.microsoft.com/en-gb/dotnet/visual-basic/language-reference/statements/if-then-else-statement
  18.    AppActivate Application.Caption
  19.     'aby bol aktivovany Excel i ked mam zapnute ine okno podla tohto navodu: https://www.mrexcel.com/board/threads/ensure-msgbox-pops-up-on-top.66245/
  20.    answer = MsgBox("Nazev novych sloupcu bude" & vbNewLine & "Obrat " & insertedValue & vbNewLine & "kusy " & insertedValue & vbNewLine & vbNewLine & "Chcete pokracovat?", vbYesNo + vbExclamation + vbDefaultButton2 + vbApplicationModal + vbMsgBoxSetForeground, "Pokracovat?")
  21.     'https://docs.microsoft.com/en-gb/office/vba/language/reference/user-interface-help/msgbox-function
  22.        If answer = vbYes Then
  23.             Call updateRepTables
  24.             'https://docs.microsoft.com/en-us/office/vba/language/concepts/getting-started/calling-sub-and-function-procedures
  25.            MsgBox "Hotovo :)"
  26.         Else
  27.             AppActivate Application.Caption
  28.             MsgBox ("Makro sa teraz vypne")
  29.             Call debugPrint
  30.             Exit Sub
  31.         End If
  32. Else
  33.     AppActivate Application.Caption
  34.     MsgBox ("Spatne vyplneny spoupec!" & vbNewLine & "Makro sa teraz vypne"), (vbOKOnly + vbCritical), ("Upozorneni")
  35.     'kazdy argument musi byt ozatvorkovany kvoli "&" (et) symbolu - program ma s nim problem, ked je viac ako jeden argument na riadku
  36.    Call debugPrint
  37.     Exit Sub
  38. End If
  39.  
  40. End Sub
  41.  
  42. Sub updateRepTables()
  43.  
  44. MsgBox ("teraz by boli updatované OZ tabulky" & vbNewLine & "Obrat " & insertedValue & vbNewLine & "kusy " & insertedValue)
  45. Call debugPrint
  46.  
  47. End Sub
  48.  
  49. Sub debugPrint()
  50. 'v "immediate window" (Ctrl+G vo VBA okne) budu vypisane hodnoty premennych ked bude tato Sub zavolana
  51. 'pomoze pri hladani chyby co sa pokazilo v makre
  52.  
  53. Debug.Print "insertedValue var[" & Format(Now, "hh:nn:ss") & "]: " & insertedValue
  54. Debug.Print "answer var[" & Format(Now, "hh:nn:ss") & "]: " & answer
  55. Debug.Print "hintLatestColumn var[" & Format(Now, "hh:nn:ss") & "]: " & hintLatestColumn
  56. 'https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/format-function-visual-basic-for-applications
  57.  
  58. End Sub
RAW Paste Data