forked from AllenMattson/VBA_personal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetWorkbook.vb
38 lines (25 loc) · 989 Bytes
/
GetWorkbook.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Public Function GetWorkbook(ByVal sFullName As String) As Workbook
Dim sFile As String
Dim wbReturn As Workbook
sFile = Dir(sFullName)
On Error Resume Next
Workbooks(sFile).Close
Set wbReturn = Workbooks(sFile)
If wbReturn Is Nothing Then
Set wbReturn = Workbooks.Open(sFullName)
End If
On Error GoTo 0
Set GetWorkbook = wbReturn
End Function
Public Function calculate_range(from_row As Long, to_row As Long, l_column As Long, _
Optional s_sheet_name As String = "calendar") As Double
Dim ws As Worksheet
Dim l_counter As Long
Dim d_result As Double
Set ws = ThisWorkbook.Worksheets(s_sheet_name)
For l_counter = from_row To to_row
Call Increment(d_result, ws.Cells(l_counter, l_column))
Next l_counter
Set ws = Nothing
calculate_range = Round(d_result, 2)
End Function