msfz751

MSystemCode

May 19th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' >>>>>>>>>>>>  MSystemCode     <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  2. ' Description:  Contains support routines developed specifically for this application.
  3. '
  4. ' Authors:      Rob Bovey, www.appspro.com
  5. '               Stephen Bullen, www.oaltd.co.uk
  6. '
  7. ' Chapter Change Overview
  8. ' Ch#   Comment
  9. ' --------------------------------------------------------------
  10. ' 05    Initial version
  11. '
  12. Option Explicit
  13. Option Private Module
  14.  
  15. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  16. ' Comments: This procedure builds the command bar for our
  17. '           application.
  18. '
  19. ' Arguments:    None
  20. '
  21. ' Date          Developer       Chap    Action
  22. ' --------------------------------------------------------------
  23. ' 06/01/08      Rob Bovey       Ch05    Initial version
  24. '
  25. Public Sub BuildCommandBars()
  26.    
  27.     Dim cbrBar As CommandBar
  28.     Dim ctlButton As CommandBarButton
  29.    
  30.     ' Create the command bar.
  31.    Set cbrBar = Application.CommandBars.Add(gsBAR_TOOLBAR, _
  32.                                         msoBarTop, False, True)
  33.     cbrBar.Visible = True
  34.    
  35.     ' Add the controls required by our application.
  36.    Set ctlButton = cbrBar.Controls.Add(msoControlButton)
  37.     ctlButton.Style = msoButtonIconAndCaption
  38.     ctlButton.Caption = "Post to Network"
  39.     ctlButton.FaceId = 107
  40.     ctlButton.OnAction = "PostTimeEntriesToNetwork"
  41.    
  42.     Set ctlButton = cbrBar.Controls.Add(msoControlButton)
  43.     ctlButton.Style = msoButtonIconAndCaption
  44.     ctlButton.Caption = "Add More Rows"
  45.     ctlButton.FaceId = 296
  46.     ctlButton.OnAction = "AddMoreRows"
  47.     ctlButton.BeginGroup = True
  48.    
  49.     Set ctlButton = cbrBar.Controls.Add(msoControlButton)
  50.     ctlButton.Style = msoButtonIconAndCaption
  51.     ctlButton.Caption = "Clear Data Entries"
  52.     ctlButton.FaceId = 47
  53.     ctlButton.OnAction = "ClearDataEntryAreas"
  54.     ctlButton.BeginGroup = True
  55.    
  56.     Set ctlButton = cbrBar.Controls.Add(msoControlButton)
  57.     ctlButton.Style = msoButtonCaption
  58.     ctlButton.Caption = "Exit PETRAS"
  59.     ctlButton.OnAction = "ExitApplication"
  60.     ctlButton.BeginGroup = True
  61.    
  62. End Sub
  63.  
  64.  
  65. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  66. ' Comments: This procedure applies the worksheet settings to all
  67. '           the worksheets in the time entry workbook.
  68. '
  69. ' Arguments:    wkbBook         The workbook to apply the settings to.
  70. '
  71. ' Date          Developer       Chap    Action
  72. ' --------------------------------------------------------------
  73. ' 06/01/08      Rob Bovey       Ch05    Initial version
  74. '
  75. Public Sub MakeWorksheetSettings(ByRef wkbBook As Workbook)
  76.  
  77.     Dim rngCell As Range
  78.     Dim rngSettingList As Range
  79.     Dim rngHideCols As Range
  80.     Dim sTabName As String
  81.     Dim vSetting As Variant
  82.     Dim wksSheet As Worksheet
  83.    
  84.     Set rngSettingList = wksUISettings.Range(gsRNG_NAME_LIST)
  85.    
  86.     For Each wksSheet In wkbBook.Worksheets
  87.    
  88.         ' The worksheet must be unprotected and visible in order
  89.        ' to make many of the settings. It will be protected and
  90.        ' hidden again automatically by the settings code if it
  91.        ' needs to be protected and/or hidden.
  92.        wksSheet.Unprotect
  93.         wksSheet.Visible = xlSheetVisible
  94.        
  95.         ' Hide any non-standard columns that need hiding.
  96.        Set rngHideCols = Nothing
  97.         On Error Resume Next
  98.         Set rngHideCols = wksSheet.Range(gsRNG_SET_HIDE_COLS)
  99.         On Error GoTo 0
  100.         If Not rngHideCols Is Nothing Then
  101.             rngHideCols.EntireColumn.Hidden = True
  102.         End If
  103.    
  104.         For Each rngCell In rngSettingList
  105.        
  106.             ' Determine if the current worksheet requires the
  107.            ' current setting.
  108.            vSetting = Empty
  109.             On Error Resume Next
  110.             If rngCell.Value = "setScrollArea" Then
  111.                 ' The scroll area setting must be treated
  112.                ' differently because it's a range object.
  113.                Set vSetting = Application.Evaluate( _
  114.                     "'" & wksSheet.Name & "'!" & rngCell.Value)
  115.             Else
  116.                 vSetting = Application.Evaluate( _
  117.                     "'" & wksSheet.Name & "'!" & rngCell.Value)
  118.             End If
  119.             On Error GoTo 0
  120.        
  121.             If Not IsEmpty(vSetting) Then
  122.                 If rngCell.Value = "setProgRows" Then
  123.                     If vSetting > 0 Then
  124.                         wksSheet.Range("A1").Resize(vSetting) _
  125.                             .EntireRow.Hidden = True
  126.                     End If
  127.                 ElseIf rngCell.Value = "setProgCols" Then
  128.                     If vSetting > 0 Then
  129.                         wksSheet.Range("A1").Resize(, _
  130.                             vSetting).EntireColumn.Hidden = True
  131.                     End If
  132.                 ElseIf rngCell.Value = "setScrollArea" Then
  133.                     wksSheet.ScrollArea = vSetting.Address
  134.                 ElseIf rngCell.Value = "setEnableSelect" Then
  135.                     wksSheet.EnableSelection = vSetting
  136.                 ElseIf rngCell.Value = "setRowColHeaders" Then
  137.                     wksSheet.Activate
  138.                     Application.ActiveWindow _
  139.                         .DisplayHeadings = vSetting
  140.                 ElseIf rngCell.Value = "setVisible" Then
  141.                     wksSheet.Visible = vSetting
  142.                 ElseIf rngCell.Value = "setProtect" Then
  143.                     If vSetting Then
  144.                         wksSheet.Protect , True, True, True
  145.                     End If
  146.                 End If
  147.             End If
  148.            
  149.         Next rngCell
  150.        
  151.     Next wksSheet
  152.    
  153.     ' Leave the Time Entry worksheet active.
  154.    sTabName = sSheetTabName(wkbBook, gsSHEET_TIME_ENTRY)
  155.     wkbBook.Worksheets(sTabName).Activate
  156.  
  157. End Sub
  158.  
  159.  
  160. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  161. ' Comments: This procedure determines in the time entry
  162. '           workbook that is used with this add-in is currently
  163. '           active. If so, it returns and object reference to
  164. '           that workbook.
  165. '
  166. ' Arguments:    wkbBook     A reference to the time entry workbook
  167. '                           if it is open, or Nothing if it isn't.
  168. '
  169. ' Returns:      Boolean     True if the time entry workbook is open.
  170. '                           False if it is not open.
  171. '
  172. ' Date          Developer       Chap    Action
  173. ' --------------------------------------------------------------
  174. ' 06/01/08      Rob Bovey       Ch05    Initial version
  175. '
  176. Public Function bIsTimeEntryBookActive(ByRef wkbBook As Workbook) As Boolean
  177.     On Error Resume Next
  178.         Set wkbBook = Nothing
  179.         Set wkbBook = Application.Workbooks(gsFILE_TIME_ENTRY)
  180.     On Error GoTo 0
  181.     If Not wkbBook Is Nothing Then
  182.         bIsTimeEntryBookActive = (wkbBook.Name = Application.ActiveWorkbook.Name)
  183.     End If
  184. End Function
Advertisement
Add Comment
Please, Sign In to add comment