Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' >>>>>>>>>>>> MSystemCode <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
- ' Description: Contains support routines developed specifically for this application.
- '
- ' Authors: Rob Bovey, www.appspro.com
- ' Stephen Bullen, www.oaltd.co.uk
- '
- ' Chapter Change Overview
- ' Ch# Comment
- ' --------------------------------------------------------------
- ' 05 Initial version
- '
- Option Explicit
- Option Private Module
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Comments: This procedure builds the command bar for our
- ' application.
- '
- ' Arguments: None
- '
- ' Date Developer Chap Action
- ' --------------------------------------------------------------
- ' 06/01/08 Rob Bovey Ch05 Initial version
- '
- Public Sub BuildCommandBars()
- Dim cbrBar As CommandBar
- Dim ctlButton As CommandBarButton
- ' Create the command bar.
- Set cbrBar = Application.CommandBars.Add(gsBAR_TOOLBAR, _
- msoBarTop, False, True)
- cbrBar.Visible = True
- ' Add the controls required by our application.
- Set ctlButton = cbrBar.Controls.Add(msoControlButton)
- ctlButton.Style = msoButtonIconAndCaption
- ctlButton.Caption = "Post to Network"
- ctlButton.FaceId = 107
- ctlButton.OnAction = "PostTimeEntriesToNetwork"
- Set ctlButton = cbrBar.Controls.Add(msoControlButton)
- ctlButton.Style = msoButtonIconAndCaption
- ctlButton.Caption = "Add More Rows"
- ctlButton.FaceId = 296
- ctlButton.OnAction = "AddMoreRows"
- ctlButton.BeginGroup = True
- Set ctlButton = cbrBar.Controls.Add(msoControlButton)
- ctlButton.Style = msoButtonIconAndCaption
- ctlButton.Caption = "Clear Data Entries"
- ctlButton.FaceId = 47
- ctlButton.OnAction = "ClearDataEntryAreas"
- ctlButton.BeginGroup = True
- Set ctlButton = cbrBar.Controls.Add(msoControlButton)
- ctlButton.Style = msoButtonCaption
- ctlButton.Caption = "Exit PETRAS"
- ctlButton.OnAction = "ExitApplication"
- ctlButton.BeginGroup = True
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Comments: This procedure applies the worksheet settings to all
- ' the worksheets in the time entry workbook.
- '
- ' Arguments: wkbBook The workbook to apply the settings to.
- '
- ' Date Developer Chap Action
- ' --------------------------------------------------------------
- ' 06/01/08 Rob Bovey Ch05 Initial version
- '
- Public Sub MakeWorksheetSettings(ByRef wkbBook As Workbook)
- Dim rngCell As Range
- Dim rngSettingList As Range
- Dim rngHideCols As Range
- Dim sTabName As String
- Dim vSetting As Variant
- Dim wksSheet As Worksheet
- Set rngSettingList = wksUISettings.Range(gsRNG_NAME_LIST)
- For Each wksSheet In wkbBook.Worksheets
- ' The worksheet must be unprotected and visible in order
- ' to make many of the settings. It will be protected and
- ' hidden again automatically by the settings code if it
- ' needs to be protected and/or hidden.
- wksSheet.Unprotect
- wksSheet.Visible = xlSheetVisible
- ' Hide any non-standard columns that need hiding.
- Set rngHideCols = Nothing
- On Error Resume Next
- Set rngHideCols = wksSheet.Range(gsRNG_SET_HIDE_COLS)
- On Error GoTo 0
- If Not rngHideCols Is Nothing Then
- rngHideCols.EntireColumn.Hidden = True
- End If
- For Each rngCell In rngSettingList
- ' Determine if the current worksheet requires the
- ' current setting.
- vSetting = Empty
- On Error Resume Next
- If rngCell.Value = "setScrollArea" Then
- ' The scroll area setting must be treated
- ' differently because it's a range object.
- Set vSetting = Application.Evaluate( _
- "'" & wksSheet.Name & "'!" & rngCell.Value)
- Else
- vSetting = Application.Evaluate( _
- "'" & wksSheet.Name & "'!" & rngCell.Value)
- End If
- On Error GoTo 0
- If Not IsEmpty(vSetting) Then
- If rngCell.Value = "setProgRows" Then
- If vSetting > 0 Then
- wksSheet.Range("A1").Resize(vSetting) _
- .EntireRow.Hidden = True
- End If
- ElseIf rngCell.Value = "setProgCols" Then
- If vSetting > 0 Then
- wksSheet.Range("A1").Resize(, _
- vSetting).EntireColumn.Hidden = True
- End If
- ElseIf rngCell.Value = "setScrollArea" Then
- wksSheet.ScrollArea = vSetting.Address
- ElseIf rngCell.Value = "setEnableSelect" Then
- wksSheet.EnableSelection = vSetting
- ElseIf rngCell.Value = "setRowColHeaders" Then
- wksSheet.Activate
- Application.ActiveWindow _
- .DisplayHeadings = vSetting
- ElseIf rngCell.Value = "setVisible" Then
- wksSheet.Visible = vSetting
- ElseIf rngCell.Value = "setProtect" Then
- If vSetting Then
- wksSheet.Protect , True, True, True
- End If
- End If
- End If
- Next rngCell
- Next wksSheet
- ' Leave the Time Entry worksheet active.
- sTabName = sSheetTabName(wkbBook, gsSHEET_TIME_ENTRY)
- wkbBook.Worksheets(sTabName).Activate
- End Sub
- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
- ' Comments: This procedure determines in the time entry
- ' workbook that is used with this add-in is currently
- ' active. If so, it returns and object reference to
- ' that workbook.
- '
- ' Arguments: wkbBook A reference to the time entry workbook
- ' if it is open, or Nothing if it isn't.
- '
- ' Returns: Boolean True if the time entry workbook is open.
- ' False if it is not open.
- '
- ' Date Developer Chap Action
- ' --------------------------------------------------------------
- ' 06/01/08 Rob Bovey Ch05 Initial version
- '
- Public Function bIsTimeEntryBookActive(ByRef wkbBook As Workbook) As Boolean
- On Error Resume Next
- Set wkbBook = Nothing
- Set wkbBook = Application.Workbooks(gsFILE_TIME_ENTRY)
- On Error GoTo 0
- If Not wkbBook Is Nothing Then
- bIsTimeEntryBookActive = (wkbBook.Name = Application.ActiveWorkbook.Name)
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment