New Text Document
New Text Document
Option VBASupport 1
'
' eBrowser related stuff
'
EbrowserInitialized = False
If Not WorksheetExists(eBrowserSheet) Then Exit Sub
Dim eb_file As String, Sh As String, cl As String, isLoaded
eb_file = arr_settings(HeaderLine8, 83)
If eb_file = "" Or File_Exists(eb_file) = False Then Exit Sub
Application.ScreenUpdating = False
Sh = ActiveSheet.Name
cl = ActiveCell.Address
With Sheets(eBrowserSheet).OLEObjects(eb_objname)
.Object.ptyModelFileName = "file:///" & eb_file
.Object.ptyAutoInit = False 'otherwise error when going to ebrowser
sheet! and search in ebm remains in loop
.Object.mthIsModelDataLoaded isLoaded
If isLoaded = True Then
EbrowserInitialized = True
Else
If load_ebr = True Then
Application.StatusBar = "Initializing eBrowser"
'do an Activate and InitializeAndDraw (both! and also in this
order!)
.Activate
.Object.mthInitializeAndDraw
.Object.mthEnableObjectEvents "Find Object in Report;", "xml"
Application.StatusBar = False 'Clear previous statusbar text
EbrowserInitialized = True
End If
End If
End With
Call sheet_sel(Sh)
Range(cl).Select
Application.ScreenUpdating = True
End Sub
With Sheets(eBrowserSheet).Buttons(1)
.Height = h
End With
With Sheets(eBrowserSheet).OLEObjects(eb_objname)
.Left = L
.Top = 0
.Height = h
.Width = W
End With
End Sub
positionID = get_positionID(Act_Cell_r)
If positionID <> "" Then
Call activate_ebrowser_sheet(Act_Sheet, Act_Cell)
Call FindPosID(positionID)
Call set_size_eb_object(1)
Exit Sub
End If
col = conv_to_number("COL_OBIREF")
If col <> 0 Then
col = arr_settings(HeaderLine2, col) + ListStartCol - 1 'get column
position
ObiRef = Act_SheetIndex & "_" & Cells(Act_Cell_r, col).Value
OneObi = ""
If FindObirefFromImportList(ObiRef, OneObi) = True Then
Call activate_ebrowser_sheet(Act_Sheet, Act_Cell)
Call ShowObirefInEbrowser(OneObi)
Call set_size_eb_object(1)
Else
' nothing found (for instance because of no obi at slaveparts)
Call sheet_sel(Act_Sheet)
Range(Act_Cell).Select
End If
Else
MsgBox "ReportGenerator debug f2" 'actually this should not occur, else:
find out what the leak is
End If
End Sub
col = conv_to_number("COL_VPO")
If col <> 0 Then
field_vpo_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_vpo_c).Value
If get_positionID <> "" Then Exit Function
End If
col = conv_to_number("COL_NAM")
If col <> 0 Then
field_nam_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_nam_c).Value
If get_positionID <> "" Then Exit Function
End If
col = conv_to_number("COL_IPO")
If col <> 0 Then
field_ipo_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_ipo_c).Value
If get_positionID <> "" Then Exit Function
End If
End Function
Width:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Width -
extra_edge_H, _
Height:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Height -
extra_edge_W)
ebrowser_object.Name = eb_objname
If Err = 0 Then
AddEbrowserObject = True
Else
AddEbrowserObject = False
End If
On Error GoTo 0 ' set back to the default error handling in VB
End Function
extra_edge_H = 6
extra_edge_W = 25
Set ebrowser_object =
ActiveSheet.OLEObjects.Add(classtype:="ebrowser.eBrowser.1", Link:=False, _
DisplayAsIcon:=False, _
Left:=0, Top:=0, _
Width:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Width -
extra_edge_H, _
Height:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Height -
extra_edge_W)
ebrowser_object.Name = eb_objname
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
End Sub
'
' 'ask for location of eBrowserfile
'
Function get_ebfile() As String
Dim eb_file As String
If WorksheetExists(eBrowserSheet) Then
eb_file = arr_settings(HeaderLine8, 83)
Else
eb_file = ""
End If
If eb_file <> "" And File_Exists(eb_file) = True Then
If MsgBox("Connect to eBrowser-file:" & Chr(10) & Chr(10) & "< " & eb_file
& " >" & Chr(10) & _
Chr(10) & "OK ?" & Chr(10), _
vbQuestion + vbYesNo, "eBrowser link") = vbNo Then
'ask user to select the eBrowser file
eb_file = Application.GetOpenFilename("Select eBrowser file
(*.ebm), *.ebm")
End If
Else
Dim fname_tmp As String
fname_tmp = ThisWorkbook.Name
fname_tmp = ThisWorkbook.Path & "\" & Left(fname_tmp, Len(fname_tmp) - 4) &
".ebm"
If File_Exists(fname_tmp) Then
eb_file = fname_tmp
If MsgBox("Connect to eBrowser-file:" & Chr(10) & Chr(10) & "< " &
eb_file & " >" & Chr(10) & _
Chr(10) & "OK ?" & Chr(10), _
vbQuestion + vbYesNo, "eBrowser link") = vbNo Then
'ask user to select the eBrowser file
eb_file = Application.GetOpenFilename("Select eBrowser file
(*.ebm), *.ebm")
End If
Else
MsgBox "Could not find eBrowser-file <" & eb_file & " >"
'ask user to select the eBrowser file:
eb_file = Application.GetOpenFilename("Select eBrowser file (*.ebm),
*.ebm")
End If
End If
Sheets("import").Visible = True
Sheets("import").Activate
Size_arr_obi = last_row_nr(1, 1) 'call to function last_row_nr()
ReDim arr_obi_sel(1 To Size_arr_obi) As String
Call Fill_arr_obi(arr_obi, Size_arr_obi)
Call Fill_arr_obiRef(arr_ObiRef, Size_arr_obi)
Sheets("import").Visible = False
If obi_sel_no = 1 Then 'if one object in set, we can exit because that one obi
will be searched
OneObiField = arr_obi_sel(1)
pos = InStr(OneObiField, "_") ' search by trying to find postion Then, if
not found this means there is only one obi in this field
If pos = 0 Then
FindObirefFromImportList = True
Exit Function
End If
End If
FindObirefFromImportList = True
Application.ScreenUpdating = True
End Function
WriteObisToATextFile = True
End Function
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthEnableModel (False)
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthSetSetVisibility
"ReportGeneratorSet", 1
'Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthShowSidebar (False)
End Sub
===================================================================================
================
'Readsettings
If Not WorksheetExists("settings") Then Exit Sub
Call init(1)
Call ReadSettings(1)
If CheckServicePack(2) Then
Call search_eb_object(1)
End If
End Sub
.Sum4.Visible = False
.Sum5.Visible = False
.Label14.Visible = False
.Label15.Visible = False
.ListToSheets.AddItem "(None)"
.Sum1.AddItem "(None)"
.Sum2.AddItem "(None)"
.Sum3.AddItem "(None)"
.Sum4.AddItem "(None)"
.Sum5.AddItem "(None)"
.Sort1.AddItem "(None)"
.Sort2.AddItem "(None)"
.Sort3.AddItem "(None)"
.SumAccording.AddItem "Use all rules, and if empty values then don't sum"
.SumAccording.AddItem "Use all rules, and if empty values then sum"
.SumAccording.AddItem "Use rules 1 & 2, and if empty then accord. rule 3"
.SumAccording.AddItem "Use rules 1, if empty: use rule 2, if empty: rule 3"
'
'set listfocus to current value
'
Dim SheetDistr_Nr As Integer, SumR1 As Integer, SumR2 As Integer, SumR3 As
Integer, SumR4 As Integer, SumR5 As Integer
Dim SortR1 As Integer, SortR2 As Integer, SortR3 As Integer, sett As String
sett = arr_settings(HeaderLine8, 1)
SheetDistr_Nr = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 2)
SumR1 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 3)
SumR2 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 4)
SumR3 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 78)
SumR4 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 79)
sett = arr_settings(HeaderLine8, 5)
SortR1 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 6)
SortR2 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 7)
SortR3 = conv_to_number(sett)
.ListToSheets.ListIndex = SheetDistr_Nr
.Sum1.ListIndex = SumR1
.Sum2.ListIndex = SumR2
.Sum3.ListIndex = SumR3
.Sum4.ListIndex = SumR4
.Sum5.ListIndex = SumR5
.Sort1.ListIndex = SortR1
.Sort2.ListIndex = SortR2
.Sort3.ListIndex = SortR3
End Sub
waitpanel.LabelProgress.Width = 0
waitpanel.Show vbModeless 'this will trigger a call to waitpanel_Activate()
PctDone = 0
PctDonePrev = 0
Call WriteSettings(1)
End Sub
===================================================================================
============
Rem Attribute VBA_ModuleType=VBAFormModule
Option VBASupport 1
Private Sub UserForm_Initialize()
Call setup_ListView
Call setup_layout
Call setup_miscellaneous
End Sub
' arr_settings(HeaderLine8, 12
arr_settings(HeaderLine8, 12) = "0" 'default
If CheckBox_total_fields.Value = False And CheckBox_sum_sheet.Value = False
Then
arr_settings(HeaderLine8, 12) = "0"
End If
If CheckBox_total_fields.Value = True And CheckBox_sum_sheet.Value = False Then
arr_settings(HeaderLine8, 12) = "1"
End If
If CheckBox_total_fields.Value = False And CheckBox_sum_sheet.Value = True Then
arr_settings(HeaderLine8, 12) = "2"
End If
If CheckBox_total_fields.Value = True And CheckBox_sum_sheet.Value = True Then
arr_settings(HeaderLine8, 12) = "3"
End If
col_nr = ComboBox_countcol.ListIndex
arr_settings(HeaderLine8, 14) = conv_colnr_to_colname(col_nr)
'report path
arr_settings(HeaderLine8, 90) = TextBox_reppath.Text
Unload Form_Settings
End Sub
Unload Form_Settings
'Form_Settings.Show
End Sub
Sub setup_ListView()
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , "", 20
ListView1.ColumnHeaders.Add , , "Title", 100
ListView1.ColumnHeaders.Add , , "Visibility", 38
ListView1.ColumnHeaders.Add , , "Tag", 80
ListView1.ColumnHeaders.Add , , "Tag from", 63
ListView1.ColumnHeaders.Add , , "Format", 65
ListView1.ColumnHeaders.Add , , "Width", 50
ListView1.ColumnHeaders.Add , , "Sum", 25
ListView1.ColumnHeaders.Add , , "Col_nr", 0
For ii = 1 To Col_ArraySize
coln = arr_settings(HeaderLine1, ii)
col_nr = arr_settings(HeaderLine2, ii) 'get column position
desc = arr_settings(HeaderLine10, ii)
desc = Replace(desc, Chr(10), " ") 'delete <Enter> from string
vis = "Hide"
If arr_settings(HeaderLine3, ii) = "SHOW" Then vis = "Show"
tag = Trim(arr_settings(HeaderLine5, ii))
If LCase(arr_settings(HeaderLine7, ii)) = "sum" Then
sumtxt = "Yes"
Else
sumtxt = "No"
End If
Next ii
Next iCounter
End Sub
End Sub
'=======================================================================
' SETTINGS-SHEET LAYOUT
'
Sub setup_layout()
ComboBox_layout.AddItem "LAYOUT1"
For Each WorkSh In ActiveWorkbook.Worksheets
If (UCase(Left(WorkSh.Name, 6)) = "LAYOUT") Then
ComboBox_layout.AddItem WorkSh.Name
End If
Next
'
'set listfocus to current value
'
Dim sett As String, nr As Integer, item As String
nr = 0
sett = arr_settings(HeaderLine8, 8)
With Me.ComboBox_layout
.ListIndex = 0 'default
For i = 0 To .ListCount - 1
item = .List(i)
If item = sett Then
.ListIndex = nr
End If
nr = nr + 1
Next i
End With
TextBox_sheet_hlines.Text = arr_settings(HeaderLine8, 9)
TextBox_sheet_hcolumns.Text = arr_settings(HeaderLine8, 10)
End Sub
CheckBox_hidetitelrow.Locked = True
CheckBox_hidetitelrow.Enabled = False
CheckBox_colwidth_via_sheet.Locked = True
CheckBox_colwidth_via_sheet.Enabled = False
Label5.Enabled = False
Label6.Enabled = False
Else
TextBox_sheet_hlines.Text = arr_settings(HeaderLine8, 9)
TextBox_sheet_hlines.Locked = False
TextBox_sheet_hlines.BackColor = &H80000005
TextBox_sheet_hcolumns.Text = arr_settings(HeaderLine8, 10)
TextBox_sheet_hcolumns.Locked = False
TextBox_sheet_hcolumns.BackColor = &H80000005
CheckBox_hidetitelrow.Locked = False
CheckBox_hidetitelrow.Enabled = True
CheckBox_colwidth_via_sheet.Locked = False
CheckBox_colwidth_via_sheet.Enabled = True
Label5.Enabled = True
Label6.Enabled = True
End If
End Sub
'=======================================================================
' SETTINGS-SHEET Miscellaneous
'
Sub setup_miscellaneous()
Dim sep As String
Select Case Trim(arr_settings(HeaderLine8, 12))
Case "0"
CheckBox_total_fields.Value = False
CheckBox_sum_sheet.Value = False
CheckBox_contweight1.Enabled = False
CheckBox_contweight2.Enabled = False
Case "1"
CheckBox_total_fields.Value = True
CheckBox_sum_sheet.Value = False
CheckBox_contweight1.Enabled = True
CheckBox_contweight2.Enabled = False
Case "2"
CheckBox_total_fields.Value = False
CheckBox_sum_sheet.Value = True
CheckBox_contweight1.Enabled = False
CheckBox_contweight2.Enabled = True
Case "3"
CheckBox_total_fields.Value = True
CheckBox_sum_sheet.Value = True
CheckBox_contweight1.Enabled = True
CheckBox_contweight2.Enabled = True
Case Else
CheckBox_total_fields.Value = False
CheckBox_sum_sheet.Value = False
CheckBox_contweight1.Enabled = False
CheckBox_contweight2.Enabled = False
End Select
Dim all_bits As String, bit1 As String, bit2 As String, bit3 As String, bit4 As
String
all_bits = arr_settings(HeaderLine8, 88)
bit1 = Mid(all_bits, 1, 1)
bit2 = Mid(all_bits, 2, 1)
bit3 = Mid(all_bits, 3, 1)
bit4 = Mid(all_bits, 4, 1)
If bit1 = "1" Then
CheckBox_CloseExcel.Value = True
Else
CheckBox_CloseExcel.Value = False
End If
If bit2 = "1" Then
CheckBox_exportCSV.Value = True
Else
CheckBox_exportCSV.Value = False
End If
If bit3 = "1" Then
CheckBox_DelSumFile.Value = True
Else
CheckBox_DelSumFile.Value = False
End If
TextBox_seperator.Locked = True
TextBox_columns.Locked = True
DirButton.Locked = True
Else
Label36.Enabled = True
TextBox_seperator.Enabled = True
Label37.Enabled = True
TextBox_columns.Enabled = True
Label38.Enabled = True
DirButton.Enabled = True
TextBox_seperator.Locked = False
TextBox_columns.Locked = False
DirButton.Locked = False
End If
TextBox_seperator.Locked = True
TextBox_columns.Locked = True
DirButton.Locked = True
Else
Label36.Enabled = True
TextBox_seperator.Enabled = True
Label37.Enabled = True
TextBox_columns.Enabled = True
Label38.Enabled = True
DirButton.Enabled = True
TextBox_seperator.Locked = False
TextBox_columns.Locked = False
DirButton.Locked = False
End If
End Sub
End Sub
Unload Form_settings2
End Sub
width_str = .ListItems(row).SubItems(6)
Select Case Right(width_str, 3)
Case "fit" 'Autofit
widnr = 0
width_value = -1
Case "Min"
widnr = 2
width_value = Left(width_str, Len(width_str) - 4)
Case "Max"
widnr = 3
width_value = Left(width_str, Len(width_str) - 4)
Case Else
widnr = 1
width_value = width_str
End Select
col_nr = .ListItems(row).SubItems(8)
End With
ComboBox_TagFrom.AddItem tagfrom_options(1, 1)
ComboBox_TagFrom.AddItem tagfrom_options(2, 1)
ComboBox_TagFrom.AddItem tagfrom_options(3, 1)
ComboBox_TagFrom.AddItem tagfrom_options(4, 1)
ComboBox_TagFrom.AddItem tagfrom_options(5, 1)
ComboBox_TagFrom.AddItem tagfrom_options(6, 1)
ComboBox_TagFrom.ListIndex = TagFrom
ComboBox_sum.AddItem "No"
ComboBox_sum.AddItem "Yes"
ComboBox_sum.ListIndex = sumnr
ComboBox_width.AddItem "Autofit"
ComboBox_width.AddItem "Fixed"
ComboBox_width.AddItem "Min."
ComboBox_width.AddItem "Max."
ComboBox_width.ListIndex = widnr
If widnr = 0 Then
TextBox_width.Locked = True
TextBox_width.BackColor = &H80000011
CommandButton_width.Enabled = False
Else
TextBox_width.Locked = False
TextBox_width.BackColor = &H80000005
CommandButton_width.Enabled = True
If width_value > 0 Then TextBox_width.Text = width_value
End If
ComboBox_Format.AddItem "String"
ComboBox_Format.AddItem "Number, 0 Dec."
ComboBox_Format.AddItem "Number, 1 Dec."
ComboBox_Format.AddItem "Number, 2 Dec."
ComboBox_Format.AddItem "Number, 3 Dec."
ComboBox_Format.AddItem "Date"
ComboBox_Format.AddItem "formula"
ComboBox_Format.ListIndex = formatnr
Call ini_formula
End Sub
End Sub
' when tag begins with a "=" then put a space in front of it to avoid
interpretation as formula
If Left(t1, 1) = "=" Then t1 = " " & t1
If Left(t2, 1) = "=" Then t2 = " " & t2
If Left(t3, 1) = "=" Then t3 = " " & t3
If Left(t4, 1) = "=" Then t4 = " " & t4
If Left(t5, 1) = "=" Then t5 = " " & t5
If Left(t6, 1) = "=" Then t6 = " " & t6
If Left(t7, 1) = "=" Then t7 = " " & t7
If Left(t8, 1) = "=" Then t8 = " " & t8
If Left(t9, 1) = "=" Then t9 = " " & t9
If Left(t10, 1) = "=" Then t10 = " " & t10
tag = t1
If t1 = "" Then
Exit Sub
Else
If t2 <> "" Then
tag = tag & "+" & t2
If t3 <> "" Then
tag = tag & "+" & t3
If t4 <> "" Then
tag = tag & "+" & t4
If t5 <> "" Then
tag = tag & "+" & t5
If t6 <> "" Then
tag = tag & "+" & t6
If t7 <> "" Then
tag = tag & "+" & t7
If t8 <> "" Then
tag = tag & "+" & t8
End If
End If
End If
End If
End If
End If
End If
End If
If t9 <> "" Then
tag = tag & "~" & t9
If t10 <> "" Then tag = tag & "+" & t10
End If
'Fix: if first char is ' then put space before it otherwise excel will
' skip this when putting value to a cell.
If Left(tag, 1) = "'" Then tag = " " & tag
End Sub
ErrorHandlingLabel:
MsgBox "Warning, formula is NOT valid: " & tagstring
Range("HH1").Value = ""
On Error GoTo 0 ' set back to the default error handling in VB
End Sub
End Sub
' fill ColHideShow() array retrieved from current sheet and setup panel
For iCounter = 1 To Col_ArraySize
item = ColTitel(iCounter)
If Columns(iCounter + ListStartCol - 1).EntireColumn.Hidden = True Then
Me.LabelHiddenCol.AddItem item
Else
Me.LabelVisibleCol.AddItem item
End If
Next iCounter
End Sub
Application.ScreenUpdating = False
Me.Hide
Dim WorkSh As Worksheet
Dim remembered_activesheetname As String, remembered_activecell As String
remembered_activesheetname = ActiveSheet.Name
remembered_activecell = ActiveCell.Address
'
'scan which items are selected to be shown, and fill array
'
With Me.LabelHiddenCol
For i = 0 To .ListCount - 1
c_nr = c_nr + 1
item = .List(i)
For iCounter = 1 To Col_ArraySize
titel_desc = arr_settings(HeaderLine10, iCounter)
titel_desc = Replace(titel_desc, Chr(10), " ") 'delete <Enter> from
string
If item = titel_desc Then
arr_settings(HeaderLine2, iCounter) = c_nr 'set new column
number
arr_settings(HeaderLine3, iCounter) = "HIDE" 'set Show/Hide
End If
Next iCounter
Next i
End With
' Declaration
Dim nr_of_sheets As Long
nr_of_sheets = Sheets.Count
ReDim TotalFields(1 To nr_of_sheets, 1 To 12) As Variant
'
' re-arrange complete sheet according new position and show/hide
'
Call ReArrange(LastRowColA, LastColRow1, SheetNr)
End If
Next
Call WriteSettings(0)
'HIDE sheets
Call HideSheets(1)
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Application.ScreenUpdating = True
Me.Hide
Unload Form_ShowColumns
End Sub
End Sub
'deselect first all items in visible column ( to see clearly which one is
added)
With Me.LabelVisibleCol
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
.Selected(i) = False
End If
Next i
End With
With Me.LabelHiddenCol
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
.Selected(i) = False
item = .List(i)
Me.LabelVisibleCol.AddItem item
Me.LabelVisibleCol.Selected(Me.LabelVisibleCol.ListCount - 1) =
True
.RemoveItem i
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
Dim i As Integer
Application.ScreenUpdating = False
'deselect first all items in visible column ( to see clearly which one is
added)
With Me.LabelHiddenCol
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
.Selected(i) = False
End If
Next i
End With
With Me.LabelVisibleCol
'li = .ListIndex
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
item = .List(i)
Me.LabelHiddenCol.AddItem item
Me.LabelHiddenCol.Selected(Me.LabelHiddenCol.ListCount - 1) = True
.RemoveItem i
End If
Next i
Dim i As Integer
With Me.LabelVisibleCol
If .ListCount > 0 Then
Application.ScreenUpdating = False
For i = 0 To .ListCount - 1
Me.LabelHiddenCol.AddItem .List(i)
Next i
.Clear
Application.ScreenUpdating = True
End If
End With
End Sub
pos = LabelVisibleCol.ListCount - 1
leaveAlone = False
If LabelVisibleCol.Selected(i) Then
If i = pos Then
leaveAlone = True
End If
pos = pos - 1
If Not leaveAlone Then
Temp = LabelVisibleCol.List(i + 1)
LabelVisibleCol.List(i + 1) = LabelVisibleCol.List(i)
LabelVisibleCol.List(i) = Temp
LabelVisibleCol.ListIndex = i + 1
LabelVisibleCol.Selected(i) = False
LabelVisibleCol.Selected(i + 1) = True
End If
End If
Next
End Sub
pos = 0
For i = 0 To LabelVisibleCol.ListCount - 1
leaveAlone = False
If LabelVisibleCol.Selected(i) Then
If i = pos Then
leaveAlone = True
End If
pos = pos + 1
'
' Just before writing the array to the sheet we now (re-)arrange the order of
the columns
'
Dim ColNr_old As Integer, ColNr_new As Integer
For iCol = 1 To nr_of_cols
ColNr_old = ColPos(iCol)
ColNr_new = arr_settings(HeaderLine2, iCol)
'
'write back to the sheet the array arr_outB
'
Call SetColFormat(1) 'set format correct otherwise value might get mutilated
(0011 becomes 11)
Range(Cells(ListStartLine, ListStartCol), Cells(LastRowColA,
LastColRow1)).Value = arr_outB
'Call Rounding(LastRowColA)
Cells(1, 1).Select 'just select "A1" in order to get active cel to so far down
End Sub
===================================================================================
============
Rem Attribute VBA_ModuleType=VBAFormModule
Option VBASupport 1
Private Sub UserForm_activate()
arr_settings(HeaderLine8, 1) = conv_colnr_to_colname(SheetDistr_Nr)
arr_settings(HeaderLine8, 2) = conv_colnr_to_colname(SumR1)
arr_settings(HeaderLine8, 3) = conv_colnr_to_colname(SumR2)
arr_settings(HeaderLine8, 4) = conv_colnr_to_colname(SumR3)
arr_settings(HeaderLine8, 5) = conv_colnr_to_colname(SortR1)
arr_settings(HeaderLine8, 6) = conv_colnr_to_colname(SortR2)
arr_settings(HeaderLine8, 7) = conv_colnr_to_colname(SortR3)
arr_settings(HeaderLine8, 78) = conv_colnr_to_colname(SumR4)
arr_settings(HeaderLine8, 79) = conv_colnr_to_colname(SumR5)
Call WriteSettings(0)
Call Progress(1)
'wait 1 sec. to give user enough time to see that 100% is reached.
'Application.Wait (Now + TimeValue("00:00:01")) 'wait 1 sec.
Unload waitpanel
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Application.ScreenUpdating = True
End If
End Sub
Private Sub CancelButton_Click()
=========================================================================
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Sub Macro_Main_Import()
'
'initialize
'
If NotAllowedToStartMacroFromHere(True) Then Exit Sub
StartedFromListControl = False
Call init(1)
' Define Importfile-name: same as current workbook, only without the addition
extension
Dim ThisWorkbookPath As String, ThisWorkbookName As String, Importfile As
String
ThisWorkbookPath = ThisWorkbook.Path
ThisWorkbookName = ThisWorkbook.Name
ThisWorkbookName = Left(ThisWorkbookName, Len(ThisWorkbookName) - 4) 'cut off
the extension ".xls"
Importfile = ThisWorkbookPath & "\" & ThisWorkbookName & f_extension
'check if importfile exists:
If File_Exists(Importfile) = False Then
MsgBox "Warning, Could not find file " & Importfile
Exit Sub
End If
Application.ScreenUpdating = False
'Application.Visible = False 'hide excel application, so only wait-panel is
visible
waitpanel.LabelProgress.Width = 0
Load waitpanel
waitpanel.Show vbModeless
Call Progress(0.01)
Call Progress(0.03)
'
'Copy content of this imported excel workbook into current sheet and delete
that workbook
'
Dim Importfile_excel As String
'check if import succeed ( if succeeded then the csv-file is opened and tabname
is always the same as the filename )
If Validate_FileImport(ThisWorkbookName, Importfile_excel) = False Then
Application.ScreenUpdating = True
Unload waitpanel
Exit Sub
End If
Application.DisplayAlerts = False 'to avoid message about clipboard when
coping
Windows(Importfile_excel).Activate 'activate imported excel workbook
Cells.Select 'select whole sheet
Selection.Copy 'copy whole sheet to clipboard
Windows(ThisWorkbook.Name).Activate 'activate current workbook
If Not WorksheetExists("import") Then
Sheets.Add 'Add new sheet
ActiveSheet.Name = "import" 'Rename new sheet
End If
Sheets("import").Select 'select the sheet with the name "import"
Cells.Select 'select whole sheet
ActiveSheet.Paste 'paste content of clipboard to the sheet
Windows(Importfile_excel).Activate 'activate imported excel workbook
'
Call Progress(0.04)
Application.CutCopyMode = False 'Clear Clipboard. VERY GOOD LINE: it will
fasten up
' following SAVE/CLOSE very much (no time
instead of 2 sec)
ActiveWindow.Close SaveChanges:=0 'close imported excel workbook
Call Progress(0.05)
Application.DisplayAlerts = True 'set original value back ("True")
'
'setup sheets; distribute import sheets to the differen sheets and setup layout
'
Dim SheetDistr_Nr As Integer, SumR1 As Integer, SumR2 As Integer, SumR3 As
Integer, SumR4 As Integer
Dim SumR5 As Integer, SortR1 As Integer, SortR2 As Integer, SortR3 As Integer,
sett As String
sett = arr_settings(HeaderLine8, 1)
SheetDistr_Nr = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 2)
SumR1 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 3)
SumR2 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 4)
SumR3 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 78)
SumR4 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 79)
SumR5 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 5)
SortR1 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 6)
SortR2 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 7)
SortR3 = conv_to_number(sett)
Dim all_bits As String, bit1 As String, bit2 As String, bit3 As String, bit4 As
String, bit5 As String
all_bits = arr_settings(HeaderLine8, 88)
bit1 = Mid(all_bits, 1, 1)
bit2 = Mid(all_bits, 2, 1)
bit3 = Mid(all_bits, 3, 1)
bit4 = Mid(all_bits, 4, 1)
bit5 = Mid(all_bits, 5, 1)
If bit2 = "1" Then Call ExportToCSV(False) ' export to CSV (and repress
messages popping up)
If bit3 = "1" Then
If File_Exists(Importfile) = True Then
Kill Importfile 'delete sumfile, (which may also be used as indicator
that it's ready to external program)
End If
End If
If bit4 = "1" Then Call CleanUp_B(False) ' Removes N-C menu, and internal
database
Call Progress(1)
Unload waitpanel
'SAVE
Application.CutCopyMode = False 'Clear Clipboard. VERY GOOD LINE: it
will fasten up
' following SAVE/CLOSE vermy much (no
time instead of 2 sec)
ActiveWorkbook.Save
Application.CutCopyMode = True ' set value back to orginal value
End Sub
End Sub
'setup lautout of import sheet (much layout is copied to other sheets form
there)
If (setup_importsheet) Then Call Layout_of_import_sheet
PctDone = 0.25
Call Progress(PctDone) 'set how much procent is done in pogress-bar
End Sub
'un-hide sheet "import", because we only can delete the old sheets when
'there is at least one sheet left visible
Sheets("import").Visible = True
If DistrColNr = 0 Then
'selected DistrColNr is 0 (= None)
Rows(2 & ":" & LastRowColA).Select
Range("A" & 2 & ":" & Column2Char(LastColRow1) & LastRowColA).Select
Selection.Copy
Sheets.Add 'Add new sheet
ActiveSheet.Name = "All" 'Rename new sheet
Range(Column2Char(ListStartCol) & ListStartLine).Select
ActiveSheet.Paste
Call Progress(0.25)
Exit Sub
End If
PctDone = 0.09
Call Progress(PctDone)
'First Sort that column in sheet "import" in order to find the unique values
Dim SortCelValue As String, SortCelValuePrev As String
Rows("2:" & LastRowColA).Select
Selection.Sort Key1:=Cells(2, DistrColNr), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
'get rid of strange character in sheetname which excel cannot handle when
renaming sheet
Dim i As Long
For i = 1 To Len(sheet_name)
Select Case Mid$(sheet_name, i, 1)
Case "?"
Mid$(sheet_name, i, 1) = "."
Case "/"
Mid$(sheet_name, i, 1) = "."
Case "\"
Mid$(sheet_name, i, 1) = "."
Case "*"
Mid$(sheet_name, i, 1) = "."
Case "["
Mid$(sheet_name, i, 1) = "."
Case "]"
Mid$(sheet_name, i, 1) = "."
Case Else
End Select
Next
If WorksheetExists(sheet_name) Then
MsgBox ("Warning, Could not add sheet <" & sheet_name & "> because this
sheet already exists.")
sheet_name = sheet_name & "_WARNING_"
End If
ActiveSheet.Name = sheet_name 'Rename new sheet
End Sub
Call Progress(0.06)
If UCase(arr_settings(HeaderLine8, 8)) <> "LAYOUT2" Then
'
' make boxlines around all cells
'
' Layout whole range: Borders (thin thickness)
Range(Cells(1, 1), Cells(LastRowColA, LastColRow1)).Select
Call NormalBorder(1)
'
' Layout rows: make left & right -borders of every row thick
'
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Call Progress(0.07)
End With
Next cel
End If
'
' Layout title row: make bold text, filling, and thick outer Border
'
Range(Cells(1, 1), Cells(1, LastColRow1)).Select
Selection.RowHeight = 35
'bold text:
For Each cel In Selection
cel.Font.Bold = True
Next cel
' filling:
With Selection.Interior
.ColorIndex = 15 'light-gray
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Call Progress(0.08)
End Sub
'
'Read settings
'
layoutsheet = UCase(arr_settings(HeaderLine8, 8))
If LCase(arr_settings(HeaderLine8, 11)) = "columnwidth_via_layoutsheet" Then
columnwidth_via_layoutsheet = True
Else
columnwidth_via_layoutsheet = False
End If
'
'copy headerlines of the layoutsheet to current sheet (content and width)
'
If WorksheetExists(layoutsheet) Then
Sheets(layoutsheet).Visible = True
Call sheet_sel(layoutsheet) 'select the sheet with that name
If columnwidth_via_layoutsheet = True Then
Dim iCounter As Long
ReDim c_width(1 To LastColRow1) As Integer
For iCounter = 1 To LastColRow1
c_width(iCounter) = Columns(iCounter).ColumnWidth
Next iCounter
End If
'
'Titel-labels: description
'
Range(Cells(Titel_row_nr, ListStartCol), Cells(Titel_row_nr,
LastColRow1)).Value = Titel_row
'
' Titel-labels: make bold text, filling, and thick outer Border
'
Range(Cells(Titel_row_nr, ListStartCol), Cells(Titel_row_nr,
LastColRow1)).Select
Selection.RowHeight = 35
'bold text:
For Each cel In Selection
cel.Font.Bold = True
Next cel
OuterBorderThick
End If
'Titel-row: HIDE
If hidetitelrow = True Then
Rows(Titel_row_nr).Select
Selection.EntireRow.Hidden = True
End If
'
' Select layoutsheet additional sheet definitions
'
Select Case layoutsheet
Case "LAYOUT1"
Call Layout1(sheetname, LastRowColA, LastColRow1, quick) 'default
layout
Case "LAYOUT2"
Call Layout2(sheetname, LastRowColA, LastColRow1, quick)
Case Else
Call Layout1(sheetname, LastRowColA, LastColRow1, quick) 'default
layout
End Select
Call set_named_cell(sheetname)
'
' Add total fields (like total mass total length, total COG)
' (also activates that sheet
'
Call addtotalfields(LastRowColA, LastColRow1, SheetNr)
'
' Column width
'
If columnwidth_via_layoutsheet = False Then
Call Columns_Width(Titel_row_nr, LastRowColA, LastColRow1)
End If
'
'DECIMALS presenting ( and also assign formula )
'
Call Rounding(LastRowColA)
'
'HIDE / SHOW the columns
'
Call Columns_HideShow(LastRowColA, LastColRow1)
'Fill_counter_column
Dim counter As Long, sett As String, cc As Integer
sett = arr_settings(HeaderLine8, 14)
counter_col_nr = conv_to_number(sett)
If counter_col_nr > 0 Then
cc = arr_settings(HeaderLine2, counter_col_nr) 'get column position
cc = cc + ListStartCol - 1
counter = 0
For rr = ListStartLine To LastRowColA
counter = counter + 1
Cells(rr, cc).Value = counter
Next rr
End If
Range("A1").Select
End Sub
'retrieve Projname from excel-filename (so, after "_" and without extension)
Dim projectname As String, UnderScorePosition As Integer, pos As Integer
projectname = ThisWorkbook.Name
UnderScorePosition = InStr(1, projectname, "_") 'get postion of "_"
If UnderScorePosition > 0 Then
pos = UnderScorePosition + 1 'begin after "_"
projectname = Mid(projectname, pos, Len(projectname) - (pos - 1) - 4)
End If
End Sub
Sub Layout2(sheetname As Worksheet, LastRowColA As Long, LastColRow1 As Long, quick
As Boolean)
'
' BORDERS: Outer border is double line and inner cells normal line
'
Range(Cells(ListStartLine, ListStartCol), Cells(LastRowColA,
LastColRow1)).Select
Call InnerNormal_OuterDouble_Border(1)
'
'BORDERS: column 16 should be total empty only left and right line is double
line
'
Dim sel_col_nr As Integer
sel_col_nr = ListStartCol + 16 - 1
Range(Cells(ListStartLine, sel_col_nr), Cells(LastRowColA, sel_col_nr)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
With Selection.Borders(xlEdgeRight)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
'
'BORDERS: column 17 should be total empty only left and right line is double
line
'
sel_col_nr = ListStartCol + 17 - 1
Range(Cells(ListStartLine, sel_col_nr), Cells(LastRowColA, sel_col_nr)).Select
With Selection.Borders(xlEdgeRight)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
'printpreview
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.Zoom = 43
.LeftMargin = Application.InchesToPoints(0.3)
.RightMargin = Application.InchesToPoints(0.3)
End With
'zoom
ActiveWindow.Zoom = 75
End Sub
End Sub
'
'Copy first lines of this imported excelWorkbook into curr sheet,& delete that
workbook
'
Dim Importfile_excel As String
'check if import succeed ( if succeeded then the csv-file is opened and tabname
is always the same as the filename )
If Validate_FileImport(ThisWorkbookName, Importfile_excel) = False Then Exit
Function
Call ReadSettings(0)
ImportSettings = True
End Function
Sheets("settings").Visible = True
Sheets("settings").Select
Call get_number_of_query_lines(1)
'only for compat reason add new columns: (because they migh miss when
rrp-file is form old version)
If Trim(arr_settings(HeaderLine1, COL_CUST41)) = "" Then
arr_settings(HeaderLine1, COL_CUST41) = "COL_CUST41"
arr_settings(HeaderLine2, COL_CUST41) = first_free_pos()
arr_settings(HeaderLine3, COL_CUST41) = "HIDE"
arr_settings(HeaderLine4, COL_CUST41) = "string"
End If
If Trim(arr_settings(HeaderLine1, COL_CUST42)) = "" Then
arr_settings(HeaderLine1, COL_CUST42) = "COL_CUST42"
arr_settings(HeaderLine2, COL_CUST42) = first_free_pos()
arr_settings(HeaderLine3, COL_CUST42) = "HIDE"
arr_settings(HeaderLine4, COL_CUST42) = "string"
End If
If Trim(arr_settings(HeaderLine1, COL_OBIREF)) = "" Then
arr_settings(HeaderLine1, COL_OBIREF) = "COL_OBIREF"
arr_settings(HeaderLine2, COL_OBIREF) = first_free_pos()
arr_settings(HeaderLine3, COL_OBIREF) = "HIDE"
arr_settings(HeaderLine4, COL_OBIREF) = "string"
End If
' Read the FORMAT-setting of the columns and store it in a public array
Call GetColFormat(1)
Sheets("settings").Visible = False
End Sub
Sub WriteSettings(SwitchBackToSheet As String)
If Not WorksheetExists("settings") Then
Exit Sub
End If
For iCol = 1 To 50
For iRow = 1 To SheetHeaderLines
EnvStartPosition = InStr(cellvalue, "$") 'get postion of "$"
If EnvStartPosition > 0 Then
EnvEndPosition = InStr(EnvStartPosition, cellvalue, " ") 'get
postion of space
If EnvEndPosition = 0 Then EnvEndPosition = Len(cellvalue)
env = Mid(cellvalue, EnvStartPosition, EnvEndPosition -
EnvStartPosition)
End If
Next iRow
Next iCol
Sheets(layout).Visible = False
End If
Sheets("settings").Visible = True
Sheets("settings").Select
Sheets("settings").Visible = False
If SwitchBackToSheet = "1" Then
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Application.ScreenUpdating = True
End If
End Sub
Application.ScreenUpdating = True
End Sub
Sub PresentDecimals(SelColumn As Integer, LastRowColA As Long, NrOfDecimals As
Integer)
Range(Cells(ListStartLine, SelColumn), Cells(LastRowColA, SelColumn)).Select
If NrOfDecimals = 0 Then Selection.NumberFormat = "0"
If NrOfDecimals = 1 Then Selection.NumberFormat = "0.0"
If NrOfDecimals = 2 Then Selection.NumberFormat = "0.00"
If NrOfDecimals = 3 Then Selection.NumberFormat = "0.000"
End Sub
End Sub
End Sub
'
'DECIMALS presenting ( and also call to assign formula)
'
Dim col_nr As Integer, declaration As String, decimals As String, col_nr_unit
As Integer
Dim celformat As String, row As Long, unit As String, pcs As String, TheFormula
As String
End If
If declaration = "formula" Then
col_nr = arr_settings(HeaderLine2, iCounter) 'get column position
col_nr = col_nr + ListStartCol - 1
TheFormula = "=" & arr_settings(HeaderLine5, iCounter)
TheFormula = Replace(TheFormula, "[R]", ListStartLine)
If TheFormula <> "" Then Call AssignFormula(col_nr, LastRowColA,
TheFormula)
End If
Next iCounter
End Sub
ErrorHandlingLabel:
MsgBox "Warning the following formula has a problem (so check via report
control the formula) : " & TheFormula
On Error GoTo 0 ' set back to the default error handling in VB
End Sub
'col width
If MinMax = "" Then
Columns(col_nr).ColumnWidth = width_str
End If
End If
Next iCounter
End Sub
get_obi_from_pipefile = ""
If InStr(guid, "-") <= 0 Then
Exit Function
End If
End Function
get_obi = obi
End Function
End If
End Function
'Select sheet
Sub sheet_sel(sh_name As String)
If sh_name <> ActiveSheet.Name Then
If WorksheetExists(sh_name) Then
If Sheets(sh_name).Visible = True Then Sheets(sh_name).Select
End If
End If
End Sub
End Sub
' SheetHeaderLines
Dim cellvalue As String, changed As Boolean
Dim arr_header As Variant 'MUST be variant
arr_header = Range(Cells(1, 1), Cells(SheetHeaderLines, LastColRow1)).Value
MsgBox "Warning: Failed fo find an open excel window with the name: " &
Chr(13) & _
"< " & Importfile_excel & " > or < " & ThisWorkbookName &
f_extension & " >" & Chr(13) & _
"Info: This is the expected result after having imported the file: " &
Chr(13) & _
" < " & ThisWorkbook.Path & "\" & ThisWorkbookName & f_extension & "
> ." & Chr(13) & _
" p.s. Current active window is: < " & ActiveWindow.Caption & " > )"
End Function
'
' creates a new menu.
'
Dim cbMenu As CommandBarControl, cbSubMenu As CommandBarControl
End With
If (CheckServicePack(2)) Then
' add menuitem to menu
With cbMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "&eBrowser link"
.OnAction = ThisWorkbook.Name & "!setup_eBrowser_link"
.Style = msoButtonIconAndCaption
.FaceId = 1577
.BeginGroup = True
End With
End If
'tip:
'instead of .FaceId = 463 you can also use your own facID's by replacing it with:
'Sheet1.Shapes("Pic1").Copy
'.PasteFace
End If
Next
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Call RemoveMenu
Call EbrowserInitialize(False, False) 'check if eBrowser is initialized
' Special treatment for ebrowsersheet while earlier it was crashing during
deletion in previous block ( probably somehow related to the activeX object)
' And also below lines should be done at the end because after this some
function somehow do not work anymore like: Application.ActiveWorkbook.Name
If WorksheetExists("eBrowser") Then
If EbrowserInitialized = False Then ' skip deleting when its active
because otherwise excel crashes
Application.DisplayAlerts = False
' Sheets("eBrowser").Delete ' does not yet work, it crashes because
eBrowser object is still somehow active. Lic even remains active till complete
excel is closed
Application.DisplayAlerts = True
End If
End If
End Sub
Sub Macro_ExportToCSV()
Application.ScreenUpdating = False
Call ExportToCSV(True)
Application.ScreenUpdating = True
End Sub
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
End Sub
' Get all defined CSV columns and it's column positions and store it in an
array
ReDim arr_csv_col(1 To 99, 1 To 3) As Variant ' 1=Colname, 2=position-nr,
3=value
csv_column_index = 0
Call get_CSV_columns(arr_csv_col, csv_column_index)
If csv_column_index = 0 Then Exit Sub
Dim cc As Integer
For cc = 1 To csv_column_index
For iCounter = 1 To nr_of_cols
ColName = arr_settings(HeaderLine1, iCounter)
If ColName = arr_csv_col(cc, 1) Then
col_pos = arr_settings(HeaderLine2, iCounter) 'get column
position
arr_csv_col(cc, 2) = col_pos
End If
Next iCounter
Next cc
'read in whole sheet into an array, and loop to all cells and store
value if the columns is needed for CSV
ReDim arr_in(1 To nr_of_rows, 1 To nr_of_cols) As Variant
arr_in = Range(Cells(ListStartLine, ListStartCol), Cells(LastRowColA,
LastColRow1)).Value
For RowIn = 1 To nr_of_rows
one_line = ""
For colin = 0 To nr_of_cols
For cc = 1 To csv_column_index
If colin = arr_csv_col(cc, 2) Then arr_csv_col(cc, 3) =
arr_in(RowIn, colin) ' store value in array
Next cc
Next colin
For cc = 1 To csv_column_index
one_line = one_line & Chr(34) & arr_csv_col(cc, 3) & Chr(34) &
separator
Next cc
one_line = Left(one_line, Len(one_line) - 1) 'skip last seperator-
char at the end of the line (requested by DamenSchelde)
next_CSV_column = "dummy"
Do While (next_CSV_column <> "")
next_CSV_column = get_next_CSV_column(CSV_columnsToDo, csv_column_index)
If next_CSV_column <> "" Then
arr_csv_col(csv_column_index, 1) = next_CSV_column
End If
Loop
End Sub
Sub Macro_ListControl()
Call init(1)
If NotAllowedToStartMacroFromHere(True) Then Exit Sub
Form_ListControl.Show
End Sub
Sub Macro_Form_ShowColumns()
Call init(1)
If NotAllowedToStartMacroFromHere(True) Then Exit Sub
If (filtersheets(ActiveSheet.Name) = True) Then
MsgBox "Not possible to start this function from sheet '" &
ActiveSheet.Name & "'" & _
Chr(10) & " ( please first select another sheet to start this
function )"
Exit Sub
End If
Form_ShowColumns.Show
End Sub
End Function
Sub Macro_WriteSettingsFile()
Call init(1)
If NotAllowedToStartMacroFromHere(True) Then Exit Sub
If Not WorksheetExists("settings") Then Exit Sub
remembered_activesheetname = ActiveSheet.Name
remembered_activecell = ActiveCell.Address
Call ReadSettings(1)
Application.ScreenUpdating = False
Sheets("settings").Visible = True
Sheets("settings").Select
Close #vFileNum
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Sheets("settings").Visible = False
Application.ScreenUpdating = True
End Sub
End Function
===================================================================================
===
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Sub ListControl(SheetDistr_Nr As Integer, SumR1 As Integer, SumR2 As Integer, _
SumR3 As Integer, SumR4 As Integer, SumR5 As Integer, SortR1 As Integer, _
SortR2 As Integer, SortR3 As Integer, setup_importsheet As Boolean)
'==========================================='
' Distribute list to sheets '
'==========================================='
Call SetupSheets(SheetDistr_Nr, setup_importsheet)
End If
Next
Call sheet_total(SheetNr)
'HIDE sheets
Call HideSheets(1)
If WorksheetExists(CurrSheet) Then
If Sheets(CurrSheet).Name <> "import" Then Sheets(CurrSheet).Activate
End If
End Sub
'
'Scan every cell in the three (sorted) suming-columns and,
' if values are same then merge the rows
'
Dim RowIn As Long, RowOut As Long, PctDoneTmp As Single, ObiRef_value As String
Dim s1 As String, s2 As String, s3 As String, obi As String
Dim base1 As String, base2 As String, base3 As String, ColNr As Integer
RowOut = 0
For RowIn = 1 To nr_of_rows
obi = ""
If check_summingrules(arr_in, arr_outA, RowIn, RowOut, SumR1, SumR2, SumR3,
SumR4, SumR5) Then
'values of the three summing-rows are equal, so merge & delete row
Call merge_lines(arr_in, arr_outA, RowIn, RowOut, nr_of_cols, obi)
Else
' just copy the line of arr_in, to a new line in arr_outA
RowOut = RowOut + 1
For i = 1 To nr_of_cols
arr_outA(RowOut, i) = arr_in(RowIn, i)
Next i
obi = arr_in(RowIn, COL_OBI)
End If
'one line in the list could be a merge of several object. Each particular
object
'on the import sheet will refer to the sheet and the OBIREF line which is
stored here:
'(is stored because after sorting the actual line numbers will be husstled
arr_outA(RowOut, COL_OBIREF) = RowOut
ObiRef_value = Sheets(sheetname).index & "_" & RowOut
Call Fill_field_Obi(arr_obi, arr_ObiRef, Size_arr_obi, ObiRef_value, obi)
Next RowIn
If 1 = 0 Then
'
'SKIP this because this method is not save. if COG=(0,0,0) we can fill it with
LOXYZ,
'this is good when COG is not defined, BUT NOT GOOD for instance when main
engine is
'placed has COG(0,0,0), then we should NOT replace this with LOXYZ
'
'
' Values are all in array so make use of this opportunity and do some
additional processing:
' when COG is not defined then take values from LocalCoordinate; LOX YZ
'
Dim cgx As String, cgy As String, cgz As String
Dim lox As String, loy As String, loz As String
For iRow = 1 To nr_of_rows
For iCol = 1 To nr_of_cols
cgx = arr_outA(COL_CGX, iCol)
cgy = arr_outA(COL_CGY, iCol)
cgz = arr_outA(COL_CGZ, iCol)
lox = arr_outA(COL_LOX, iCol)
loy = arr_outA(COL_LOY, iCol)
loz = arr_outA(COL_LOZ, iCol)
'
' if .... then ....
'
Next iCol
Next iRow
End If
'
' Just before writing the array to the sheet we now (re-)arrange the order of
the columns
'
'BE AWARE THAT HeaderLine2 contains all rowvalues (if one is missing then it is
not declared)
'
For iCol = 1 To nr_of_cols
ColNr = arr_settings(HeaderLine2, iCol)
For iRow = 1 To nr_of_rows
arr_outB(iRow, ColNr) = arr_outA(iRow, iCol)
Next iRow
Next iCol
'
'write back to the sheet the array arr_outB
'
Call SetColFormat(1) 'set format correct otherwise value might get mutilated
(0011 becomes 11)
Range(Cells(ListStartLine, ListStartCol), Cells(LastRowColA,
LastColRow1)).Value = arr_outB
Cells(1, 1).Select 'just select "A1" in order to get active cel to so far down
End Sub
check_summingrules = False
'no lines yes copied to arr_outA so nothing to compare yes, therefor exit
If RowOut = 0 Then Exit Function
'refering to the two rows; check if the three cell-values are the same
Dim s1 As String, s2 As String, s3 As String, s4 As String, s5 As String,
SumAccording As String
Dim base1 As String, base2 As String, base3 As String, base4 As String, base5
As String
base1 = ""
base2 = ""
base3 = ""
base4 = ""
base5 = ""
s1 = ""
s2 = ""
s3 = ""
s4 = ""
s5 = ""
If SumR1 > 0 Then base1 = arr_in(RowIn, SumR1)
If SumR2 > 0 Then base2 = arr_in(RowIn, SumR2)
If SumR3 > 0 Then base3 = arr_in(RowIn, SumR3)
If SumR4 > 0 Then base4 = arr_in(RowIn, SumR4)
If SumR5 > 0 Then base5 = arr_in(RowIn, SumR5)
If SumR1 > 0 Then s1 = arr_outA(RowOut, SumR1)
If SumR2 > 0 Then s2 = arr_outA(RowOut, SumR2)
If SumR3 > 0 Then s3 = arr_outA(RowOut, SumR3)
If SumR4 > 0 Then s4 = arr_outA(RowOut, SumR4)
If SumR5 > 0 Then s5 = arr_outA(RowOut, SumR5)
SumAccording = arr_settings(HeaderLine8, 91)
If SumAccording = "0" Or SumAccording = "1" Then
If (base1 = s1) And (base2 = s2) And (base3 = s3) And (base4 = s4) And
(base5 = s5) Then
check_summingrules = True
If SumAccording = "0" Then
'Don't Sum the EmptyFields
If (base1 = "") And (base2 = "") And (base3 = "") And (base4 = "")
And (base5 = "") Then check_summingrules = False
End If
End If
End If
End Function
' First all the columns that should be summed with a weightfactor according to
another column
' (this needs to be done first otherwise that other columns is already summed)
For i = 1 To nr_of_cols
Select Case i
End Select
Next i
Case COL_OBI
' put one objectID in the column in case of different values.
' ( not all objectId because that will be too much for big lists)
temp_str1 = arr_in(RowIn, i)
temp_str2 = arr_outA(RowOut, i)
If temp_str1 <> "" And temp_str2 = "" Then
arr_outA(RowOut, i) = temp_str1
End If
Case COL_OBIREF
'do nothing (is done elsewhere)
Case COL_BLK
' in case of different values don't clear it.
' and in case one of the value is empty then take the not-empty one.
temp_str1 = arr_in(RowIn, i)
temp_str2 = arr_outA(RowOut, i)
If temp_str1 <> "" And temp_str2 = "" Then
arr_outA(RowOut, i) = temp_str1
End If
Case Else
'clear field if contents are different
If arr_outA(RowOut, i) <> arr_in(RowIn, i) Then
arr_outA(RowOut, i) = ""
If i = COL_CAT Then arr_outA(RowOut, i) = "Several"
End If
End Select
Next i
obi = arr_in(RowIn, COL_OBI)
End Sub
End Sub
'select
Rows(br & ":" & LastRowColA).Select
If (False) Then
'STATUS-BAR
Const NumBars As Integer = 30 ' # of characters in the bar
Dim FBar As Integer, BBar As Integer
FBar = CInt(ProcentDone * NumBars)
BBar = NumBars - FBar
BarText = format(ProcentDone, "0%")
Application.StatusBar = BarText & Application.Rept(">", FBar) & _
Application.Rept(".", BBar)
If ProcentDone = 1 Then Application.StatusBar = False
End If
PctDonePrev = ProcentDone
End If
End Sub
End If
End Function
End Function
End Function
Function last_col_nr(begin_col As Integer) As Integer
'
' get the last Col-nr.
'
last_col_nr = begin_col + Col_ArraySize - 1
If last_col_nr < begin_col Then last_col_nr = begin_col
End Function
'HIDE sheets
For Each WorkSh In ActiveWorkbook.Worksheets
If (WorkSh_Name = "eBrowser") Then
If (EbrowserInitialized = False) Then Sheets(WorkSh.Name).Visible =
False
Else
If (filtersheets(WorkSh.Name) = True) Then
Sheets(WorkSh.Name).Visible = False
End If
End If
EbrowserInitialized = False
eBrowserSheet = "eBrowser"
eb_objname = "eBrowserObject"
PctDone = 0
PctDonePrev = 0
LayoutSetting_just_changed = False
Col_ArraySize = 91
f_extension = "_sum"
SheetHeaderLines = 0
SheetHeaderColumns = 0
ListStartLine = SheetHeaderLines + 3 ' begin-row of the list-area
ListStartCol = SheetHeaderColumns + 1 ' begin-column of the list-area
QueryLinesMax = 500
HeaderLines = 11
HeaderLine1 = 1 'contains the internal NAME of the column (COL_..)
HeaderLine2 = 2 'contains col POSITION (which is first col, second, third,
etc.)
HeaderLine3 = 3 'whether the column should be SHOWN or hidden
HeaderLine4 = 4 'FORMAT of the column and how many decimals (string / float0 /
float2 / date)
HeaderLine5 = 5 'the CUSTOM TAGS for the custom columns
HeaderLine6 = 6 '(MAX) WIDTH of the columns
' empty or "AUTOFIT" means autofit columnwidth
' value means fixed columnwidth
'MIN + value means MIN columnwidth
'MAX + value means MAX columnwidth
HeaderLine7 = 7 'Columns which should be SUMMED in case lines where merged.
Only for CUSTOM col!
HeaderLine8 = 8 'SETTINGS can be found in this row in the following cells:
' 1 - distr,
' 2 - SummingR1,
' 3 - SummingR2,
' 4 - SummingR3,
' 5 - SortR1,
' 6 - SortR2,
' 7 - SortR3,
' 8 - LayoutVersion
' 9 - SheetHeaderLines
' 10 - SheetHeaderColumns
' 11 - columnwidth_via_layoutsheet (if it has this value then
set col same as sheet)
' 12 - addtotalfields:
' Value | on every sheet | include summary sheet
' 0 | NO | NO
' 1 | YES | NO
' 2 | NO | YES
' 3 | YES | YES
COL_CAT = 1
COL_PLI = 2
COL_SPN = 3
COL_SYS = 4
COL_DE = 5
COL_DD = 6
COL_FII = 7
COL_ART = 8
COL_VPO = 9
COL_BPL = 10
COL_LEN = 11
COL_QTY = 12
COL_GT = 13
COL_MAS = 14
COL_CGX = 15
COL_CGY = 16
COL_CGZ = 17
COL_CONM = 18
COL_CONX = 19
COL_CONY = 20
COL_CONZ = 21
COL_FLUID = 22
COL_CONV = 23
COL_TOTM = 24
COL_TOTX = 25
COL_TOTY = 26
COL_TOTZ = 27
COL_OBI = 28
COL_PID = 29
COL_CORP = 30
COL_DIMT = 31
COL_SLAVE = 32
COL_MAT = 33
COL_SPC = 34
COL_CMD = 35
COL_NAM = 36
COL_LOX = 37
COL_LOY = 38
COL_LOZ = 39
COL_HUL = 40
COL_MTH = 41
COL_SCO = 42
COL_UNIT = 43
COL_IDN = 44
COL_MOT = 45
COL_SPO = 46
COL_BLK = 47
COL_IPO = 48
COL_CUST1 = 49
COL_CUST2 = 50
COL_CUST3 = 51
COL_CUST4 = 52
COL_CUST5 = 53
COL_CUST6 = 54
COL_CUST7 = 55
COL_CUST8 = 56
COL_CUST9 = 57
COL_CUST10 = 58
COL_CUST11 = 59
COL_CUST12 = 60
COL_CUST13 = 61
COL_CUST14 = 62
COL_CUST15 = 63
COL_CUST16 = 64
COL_CUST17 = 65
COL_CUST18 = 66
COL_CUST19 = 67
COL_CUST20 = 68
COL_CUST21 = 69
COL_CUST22 = 70
COL_CUST23 = 71
COL_CUST24 = 72
COL_CUST25 = 73
COL_CUST26 = 74
COL_CUST27 = 75
COL_CUST28 = 76
COL_CUST29 = 77
COL_CUST30 = 78
COL_CUST31 = 79
COL_CUST32 = 80
COL_CUST33 = 81
COL_CUST34 = 82
COL_CUST35 = 83
COL_CUST36 = 84
COL_CUST37 = 85
COL_CUST38 = 86
COL_CUST39 = 87
COL_CUST40 = 88
COL_CUST41 = 89
COL_CUST42 = 90
COL_OBIREF = 91
End Sub
=================================================================================
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Sub addtotalfields(LastRowColA As Long, LastColRow1 As Long, SheetNr As Long)
'
' Define Total fields in sheet
'
Dim add_total_fields As Integer
add_total_fields_nr = arr_settings(HeaderLine8, 12)
If add_total_fields_nr > 3 Then add_total_fields_nr = 0
If add_total_fields_nr = 0 Then Exit Sub
'
' First define which are the first 3 visible columns
'
Dim col_nr As Integer
ReDim ColPos_sorted(1 To Col_ArraySize) As Integer
'
'all col-positions in order (first column first, then second, etc)
For iCounter = 1 To Col_ArraySize
col_nr = arr_settings(HeaderLine2, iCounter) 'get column position
ColPos_sorted(col_nr) = iCounter
Next iCounter
'
'now the columns is sorted and check on for one if that columns is SHOWN
Dim COL_TOT0 As Integer, COL_TOT1 As Integer, col_tot2 As Integer
COL_TOT0 = 0
COL_TOT1 = 0
col_tot2 = 0
For iCounter = 1 To Col_ArraySize
col_nr = ColPos_sorted(iCounter)
If col_nr = 0 Then MsgBox "Warning, was not able to find a columnposition
for column " & iCounter & ". Possible cause is a non-unique description."
If arr_settings(HeaderLine3, col_nr) = "SHOW" Then
If COL_TOT0 = 0 Then
COL_TOT0 = arr_settings(HeaderLine2, col_nr) + ListStartCol - 1
Else
If COL_TOT1 = 0 Then
COL_TOT1 = arr_settings(HeaderLine2, col_nr) + ListStartCol - 1
Else
If col_tot2 = 0 Then col_tot2 = arr_settings(HeaderLine2,
col_nr) + ListStartCol - 1
End If
End If
End If
Next iCounter
'min values:
If COL_TOT0 < ListStartCol + 0 Then COL_TOT0 = ListStartCol + 0
If COL_TOT1 < ListStartCol + 1 Then COL_TOT1 = ListStartCol + 1
If col_tot2 < ListStartCol + 2 Then col_tot2 = ListStartCol + 2
'
'Put Border around it with double line and set format of cells to numbers
'
Range(Cells(LastRowColA + 7, COL_TOT1), Cells(LastRowColA + 10,
col_tot2)).Select
Call InnerNormal_OuterDouble_Border(1)
Selection.NumberFormat = "General"
Range(Cells(LastRowColA + 2, COL_TOT1), Cells(LastRowColA + 6,
col_tot2)).Select
Call InnerNormal_OuterDouble_Border(1)
Selection.NumberFormat = "General"
Range(Cells(LastRowColA + 2, COL_TOT1), Cells(LastRowColA + 19, COL_TOT1)) _
.Font.Italic = True
Range(Cells(LastRowColA + 2, col_tot2), Cells(LastRowColA + 19, col_tot2)) _
.NumberFormat = "General"
'
' Fill total fields onto sheet
'
Dim mm As Integer
Dim Cel_Formula1 As String, Cel_Formula2 As String, Cel_Formula3 As String
Dim Cel_Formula4 As String, Cel_Formula5 As String
Dim Cel_Formtxt1 As String, Cel_Formtxt2 As String, Cel_Formtxt3 As String
Dim Cel_Formtxt4 As String, Cel_Formtxt5 As String
Dim COL_char As String, COL_char_sum As String, COL_char_sum_cont As String
Dim TotLen As Double
' Define COL_char of the Weight and of the Total Weight (incl content weight)
'
col_nr = arr_settings(HeaderLine2, COL_MAS) 'get column position
col_nr = col_nr + ListStartCol - 1
COL_char_sum = Column2Char(col_nr)
'
col_nr = arr_settings(HeaderLine2, COL_TOTM) 'get column position
col_nr = col_nr + ListStartCol - 1
COL_char_sum_cont = Column2Char(col_nr)
'temp. put weight sum in field to be used to check if this value >0
Cel_Formula2 = "=SUM(" & COL_char_sum & ListStartLine & ":" & _
COL_char_sum & LastRowColA & ")"
Cells(LastRowColA + 3, col_tot2).Formula = Cel_Formula2
'Total COG X
col_nr = arr_settings(HeaderLine2, COL_CGX) 'get column position
col_nr = col_nr + ListStartCol - 1
COL_char = Column2Char(col_nr)
Cells(LastRowColA + 4, COL_TOT1).Value = " COG x"
Cells(LastRowColA + 13, COL_TOT1).Value = " COG x"
Cel_Formtxt3 = _
"=ROUND(SUMPRODUCT(" & COL_char & ListStartLine & ":" & COL_char & _
LastRowColA & "," & COL_char_sum & ListStartLine & ":" & _
COL_char_sum & LastRowColA & " )/ SUM(" & COL_char_sum & _
ListStartLine & ":" & COL_char_sum & LastRowColA & _
")/" & mm & ",2)& TEXT("" m"",0)"
Cel_Formula3 = _
"=ROUND(SUMPRODUCT(" & COL_char & ListStartLine & ":" & COL_char & _
LastRowColA & "," & COL_char_sum & ListStartLine & ":" & _
COL_char_sum & LastRowColA & " )/ SUM(" & COL_char_sum & _
ListStartLine & ":" & COL_char_sum & LastRowColA & _
")/" & mm & ",2)"
Cells(LastRowColA + 4, col_tot2).Formula = Cel_Formtxt3
Cells(LastRowColA + 13, col_tot2).Formula = Cel_Formula3
'Total COG Y
col_nr = arr_settings(HeaderLine2, COL_CGY) 'get column position
col_nr = col_nr + ListStartCol - 1
COL_char = Column2Char(col_nr)
Cells(LastRowColA + 5, COL_TOT1).Value = " COG y"
Cells(LastRowColA + 14, COL_TOT1).Value = " COG y"
Cel_Formtxt4 = _
"=ROUND(SUMPRODUCT(" & COL_char & ListStartLine & ":" & COL_char & _
LastRowColA & "," & COL_char_sum & ListStartLine & ":" & _
COL_char_sum & LastRowColA & " )/ SUM(" & COL_char_sum & _
ListStartLine & ":" & COL_char_sum & LastRowColA & _
")/" & mm & ",2)& TEXT("" m"",0)"
Cel_Formula4 = _
"=ROUND(SUMPRODUCT(" & COL_char & ListStartLine & ":" & COL_char & _
LastRowColA & "," & COL_char_sum & ListStartLine & ":" & _
COL_char_sum & LastRowColA & " )/ SUM(" & COL_char_sum & _
ListStartLine & ":" & COL_char_sum & LastRowColA & _
")/" & mm & ",2)"
Cells(LastRowColA + 5, col_tot2).Formula = Cel_Formtxt4
Cells(LastRowColA + 14, col_tot2).Formula = Cel_Formula4
'Total COG Z
col_nr = arr_settings(HeaderLine2, COL_CGZ) 'get column position
col_nr = col_nr + ListStartCol - 1
COL_char = Column2Char(col_nr)
Cells(LastRowColA + 6, COL_TOT1).Value = " COG z"
Cells(LastRowColA + 15, COL_TOT1).Value = " COG z"
Cel_Formtxt5 = _
"=ROUND(SUMPRODUCT(" & COL_char & ListStartLine & ":" & COL_char & _
LastRowColA & "," & COL_char_sum & ListStartLine & ":" & _
COL_char_sum & LastRowColA & " )/ SUM(" & COL_char_sum & _
ListStartLine & ":" & COL_char_sum & LastRowColA & _
")/" & mm & ",2)& TEXT("" m"",0)"
Cel_Formula5 = _
"=ROUND(SUMPRODUCT(" & COL_char & ListStartLine & ":" & COL_char & _
LastRowColA & "," & COL_char_sum & ListStartLine & ":" & _
COL_char_sum & LastRowColA & " )/ SUM(" & COL_char_sum & _
ListStartLine & ":" & COL_char_sum & LastRowColA & _
")/" & mm & ",2)"
Cells(LastRowColA + 6, col_tot2).Formula = Cel_Formtxt5
Cells(LastRowColA + 15, col_tot2).Formula = Cel_Formula5
Else
Cells(LastRowColA + 4, COL_TOT1).Value = " "
Cells(LastRowColA + 4, col_tot2).Value = " "
Cells(LastRowColA + 5, COL_TOT1).Value = " "
Cells(LastRowColA + 5, col_tot2).Value = " "
Cells(LastRowColA + 6, COL_TOT1).Value = " "
Cells(LastRowColA + 6, col_tot2).Value = " "
' Weight
Cells(LastRowColA + 3, COL_TOT1).Value = " Total Weight"
Cells(LastRowColA + 12, COL_TOT1).Value = " Total Weight"
Cells(LastRowColA + 3, col_tot2).Formula = _
"=ROUND(SUM(" & COL_char_sum & ListStartLine & ":" & COL_char_sum & _
LastRowColA & "),1)& TEXT("" Kg"",0)"
Cells(LastRowColA + 12, col_tot2).Formula = _
"=ROUND(SUM(" & COL_char_sum & ListStartLine & ":" & COL_char_sum & _
LastRowColA & "),1)"
' Weight (incl. content weight)
Cells(LastRowColA + 7, COL_TOT1).Value = " Total Weight (incl. content)"
Cells(LastRowColA + 16, COL_TOT1).Value = " Total Weight (incl. content)"
Cells(LastRowColA + 7, col_tot2).Formula = _
"=ROUND(SUM(" & COL_char_sum_cont & ListStartLine & ":" & COL_char_sum_cont
& _
LastRowColA & "),1)& TEXT("" Kg"",0)"
Cells(LastRowColA + 16, col_tot2).Formula = _
"=ROUND(SUM(" & COL_char_sum_cont & ListStartLine & ":" & COL_char_sum_cont
& _
LastRowColA & "),1)"
'
Dim curr_sheetn As String
curr_sheetn = ActiveSheet.Name
TotalFields(SheetNr, 1) = curr_sheetn
TotalFields(SheetNr, 2) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 11,
col_tot2).Address
TotalFields(SheetNr, 3) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 12,
col_tot2).Address
TotalFields(SheetNr, 4) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 13,
col_tot2).Address
TotalFields(SheetNr, 5) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 14,
col_tot2).Address
TotalFields(SheetNr, 6) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 15,
col_tot2).Address
TotalFields(SheetNr, 7) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 16,
col_tot2).Address
TotalFields(SheetNr, 8) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 17,
col_tot2).Address
TotalFields(SheetNr, 9) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 18,
col_tot2).Address
TotalFields(SheetNr, 10) = "='" & curr_sheetn & "'!" & Cells(LastRowColA + 19,
col_tot2).Address
TotalFields(SheetNr, 11) = ""
TotalFields(SheetNr, 12) = ""
End Sub
For rr = 1 To SheetNr
Hlink = "'" & TotalFields(rr, 1) & "'!A1"
Hlink_txt = TotalFields(rr, 1)
ActiveSheet.Hyperlinks.Add _
Anchor:=Cells(startrow + rr - 1, startcol + 12 - 1), Address:="", _
SubAddress:=Hlink, TextToDisplay:=Hlink_txt
Next rr
'
' Fill total fields onto sheet
'
Dim Cel_Formula1 As String, Cel_Formula2 As String, Cel_Formula3 As String
Dim Cel_Formula4 As String, Cel_Formula5 As String
Dim Cel_Formtxt1 As String, Cel_Formtxt2 As String, Cel_Formtxt3 As String
Dim Cel_Formtxt4 As String, Cel_Formtxt5 As String
Dim COL_char As String, COL_char2 As String, COL_char_sum As String
Dim TotLen As Double, COL_char_sum_cont As String
Dim col_tot As Integer, col_tot2 As Integer, row_tot As Integer, col_nr As
Integer
col_tot = 4
col_tot2 = 9
row_tot = 2
col_nr = col_tot - 1
COL_char = Column2Char(col_nr)
Cel_Formula1 = "=ROUND(SUM(" & COL_char & startrow & _
":" & COL_char & endrow & "),2)& TEXT("" m"",0)"
Cells(row_tot, col_tot).Formula = Cel_Formula1
'temp. put weight sum in field to be used to check if this value >0
col_nr = startcol + 3 - 1
COL_char_sum = Column2Char(col_nr)
Cel_Formula2 = "=SUM(" & COL_char_sum & startrow & ":" & _
COL_char_sum & endrow & ")"
Cells(row_tot + 1, col_tot).Formula = Cel_Formula2
col_nr = startcol + 7 - 1
COL_char_sum_cont = Column2Char(col_nr)
'Total COG X
col_nr = startcol + 4 - 1
COL_char = Column2Char(col_nr)
Cel_Formula3 = _
"=ROUND(SUMPRODUCT(" & COL_char & startrow & ":" & COL_char & _
endrow & "," & COL_char_sum & startrow & ":" & _
COL_char_sum & endrow & " )/ SUM(" & COL_char_sum & _
startrow & ":" & COL_char_sum & endrow & _
"),2)& TEXT("" m"",0)"
Cells(row_tot + 2, col_tot).Formula = Cel_Formula3
'Total COG Y
col_nr = startcol + 5 - 1
COL_char = Column2Char(col_nr)
Cel_Formula4 = _
"=ROUND(SUMPRODUCT(" & COL_char & startrow & ":" & COL_char & _
endrow & "," & COL_char_sum & startrow & ":" & _
COL_char_sum & endrow & " )/ SUM(" & COL_char_sum & _
startrow & ":" & COL_char_sum & endrow & _
"),2)& TEXT("" m"",0)"
Cells(row_tot + 3, col_tot).Formula = Cel_Formula4
'Total COG Z
col_nr = startcol + 6 - 1
COL_char = Column2Char(col_nr)
Cel_Formula5 = _
"=ROUND(SUMPRODUCT(" & COL_char & startrow & ":" & COL_char & _
endrow & "," & COL_char_sum & startrow & ":" & _
COL_char_sum & endrow & " )/ SUM(" & COL_char_sum & _
startrow & ":" & COL_char_sum & endrow & _
"),2)& TEXT("" m"",0)"
Cells(row_tot + 4, col_tot).Formula = Cel_Formula5
Else
Cells(row_tot + 2, col_tot).Value = ""
Cells(row_tot + 3, col_tot).Value = ""
Cells(row_tot + 4, col_tot).Value = ""
Cells(row_tot, col_tot2).Value = ""
Cells(row_tot, col_tot2).Value = ""
Cells(row_tot, col_tot2).Value = ""
Rows(endrow + 2 & ":" & endrow + 4).EntireRow.Hidden = True
End If
'weight
Cells(row_tot + 1, col_tot).Formula = _
"=ROUND(SUM(" & COL_char_sum & startrow & ":" & COL_char_sum & _
endrow & "),1)& TEXT("" Kg"",0)"
'
'fill title of the column that contains the sheet-values
'
Dim sett As String, distr_col_name As String
sett = arr_settings(HeaderLine8, 1)
SheetDistr_Nr = conv_to_number(sett)
If SheetDistr_Nr <> 0 Then
distr_col_name = arr_settings(HeaderLine10, SheetDistr_Nr) 'get column desc
Else
distr_col_name = "Sheet"
End If
Cells(1, 1).Select 'just select "A1" in order to get active cel to so far down
End Sub
End Sub
=============================================================================
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
'
' eBrowser related stuff
'
EbrowserInitialized = False
If Not WorksheetExists(eBrowserSheet) Then Exit Sub
Dim eb_file As String, Sh As String, cl As String, isLoaded
eb_file = arr_settings(HeaderLine8, 83)
If eb_file = "" Or File_Exists(eb_file) = False Then Exit Sub
Application.ScreenUpdating = False
Sh = ActiveSheet.Name
cl = ActiveCell.Address
With Sheets(eBrowserSheet).OLEObjects(eb_objname)
.Object.ptyModelFileName = "file:///" & eb_file
.Object.ptyAutoInit = False 'otherwise error when going to ebrowser
sheet! and search in ebm remains in loop
.Object.mthIsModelDataLoaded isLoaded
If isLoaded = True Then
EbrowserInitialized = True
Else
If load_ebr = True Then
Application.StatusBar = "Initializing eBrowser"
'do an Activate and InitializeAndDraw (both! and also in this
order!)
.Activate
.Object.mthInitializeAndDraw
.Object.mthEnableObjectEvents "Find Object in Report;", "xml"
Application.StatusBar = False 'Clear previous statusbar text
EbrowserInitialized = True
End If
End If
End With
Call sheet_sel(Sh)
Range(cl).Select
Application.ScreenUpdating = True
End Sub
With Sheets(eBrowserSheet).Buttons(1)
.Height = h
End With
With Sheets(eBrowserSheet).OLEObjects(eb_objname)
.Left = L
.Top = 0
.Height = h
.Width = W
End With
End Sub
positionID = get_positionID(Act_Cell_r)
If positionID <> "" Then
Call activate_ebrowser_sheet(Act_Sheet, Act_Cell)
Call FindPosID(positionID)
Call set_size_eb_object(1)
Exit Sub
End If
col = conv_to_number("COL_OBIREF")
If col <> 0 Then
col = arr_settings(HeaderLine2, col) + ListStartCol - 1 'get column
position
ObiRef = Act_SheetIndex & "_" & Cells(Act_Cell_r, col).Value
OneObi = ""
If FindObirefFromImportList(ObiRef, OneObi) = True Then
Call activate_ebrowser_sheet(Act_Sheet, Act_Cell)
Call ShowObirefInEbrowser(OneObi)
Call set_size_eb_object(1)
Else
' nothing found (for instance because of no obi at slaveparts)
Call sheet_sel(Act_Sheet)
Range(Act_Cell).Select
End If
Else
MsgBox "ReportGenerator debug f2" 'actually this should not occur, else:
find out what the leak is
End If
End Sub
col = conv_to_number("COL_VPO")
If col <> 0 Then
field_vpo_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_vpo_c).Value
If get_positionID <> "" Then Exit Function
End If
col = conv_to_number("COL_NAM")
If col <> 0 Then
field_nam_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_nam_c).Value
If get_positionID <> "" Then Exit Function
End If
col = conv_to_number("COL_IPO")
If col <> 0 Then
field_ipo_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_ipo_c).Value
If get_positionID <> "" Then Exit Function
End If
End Function
Call set_size_eb_object(1)
Sheets(eBrowserSheet).Cells(1, 1).Value = "button"
Sheets(eBrowserSheet).Cells(1, 2).Value = Act_Sheet
Sheets(eBrowserSheet).Cells(1, 3).Value = Act_Cell
End Sub
Sub FindPosID(positionID As String)
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthLocateByPosition
positionID, 0
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthShowSidebar (True)
End Sub
Width:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Width -
extra_edge_H, _
Height:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Height -
extra_edge_W)
ebrowser_object.Name = eb_objname
If Err = 0 Then
AddEbrowserObject = True
Else
AddEbrowserObject = False
End If
On Error GoTo 0 ' set back to the default error handling in VB
End Function
extra_edge_H = 6
extra_edge_W = 25
Set ebrowser_object =
ActiveSheet.OLEObjects.Add(classtype:="ebrowser.eBrowser.1", Link:=False, _
DisplayAsIcon:=False, _
Left:=0, Top:=0, _
Width:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Width -
extra_edge_H, _
Height:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Height -
extra_edge_W)
ebrowser_object.Name = eb_objname
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
End Sub
'
' 'ask for location of eBrowserfile
'
Function get_ebfile() As String
Dim eb_file As String
If WorksheetExists(eBrowserSheet) Then
eb_file = arr_settings(HeaderLine8, 83)
Else
eb_file = ""
End If
If eb_file <> "" And File_Exists(eb_file) = True Then
If MsgBox("Connect to eBrowser-file:" & Chr(10) & Chr(10) & "< " & eb_file
& " >" & Chr(10) & _
Chr(10) & "OK ?" & Chr(10), _
vbQuestion + vbYesNo, "eBrowser link") = vbNo Then
'ask user to select the eBrowser file
eb_file = Application.GetOpenFilename("Select eBrowser file
(*.ebm), *.ebm")
End If
Else
Dim fname_tmp As String
fname_tmp = ThisWorkbook.Name
fname_tmp = ThisWorkbook.Path & "\" & Left(fname_tmp, Len(fname_tmp) - 4) &
".ebm"
If File_Exists(fname_tmp) Then
eb_file = fname_tmp
If MsgBox("Connect to eBrowser-file:" & Chr(10) & Chr(10) & "< " &
eb_file & " >" & Chr(10) & _
Chr(10) & "OK ?" & Chr(10), _
vbQuestion + vbYesNo, "eBrowser link") = vbNo Then
'ask user to select the eBrowser file
eb_file = Application.GetOpenFilename("Select eBrowser file
(*.ebm), *.ebm")
End If
Else
MsgBox "Could not find eBrowser-file <" & eb_file & " >"
'ask user to select the eBrowser file:
eb_file = Application.GetOpenFilename("Select eBrowser file (*.ebm),
*.ebm")
End If
End If
Sheets("import").Visible = True
Sheets("import").Activate
Size_arr_obi = last_row_nr(1, 1) 'call to function last_row_nr()
ReDim arr_obi_sel(1 To Size_arr_obi) As String
Call Fill_arr_obi(arr_obi, Size_arr_obi)
Call Fill_arr_obiRef(arr_ObiRef, Size_arr_obi)
Sheets("import").Visible = False
If obi_sel_no = 1 Then 'if one object in set, we can exit because that one obi
will be searched
OneObiField = arr_obi_sel(1)
pos = InStr(OneObiField, "_") ' search by trying to find postion Then, if
not found this means there is only one obi in this field
If pos = 0 Then
FindObirefFromImportList = True
Exit Function
End If
End If
FindObirefFromImportList = True
Application.ScreenUpdating = True
End Function
WriteObisToATextFile = True
End Function
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthEnableModel (False)
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthSetSetVisibility
"ReportGeneratorSet", 1
'Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthShowSidebar (False)
End Sub
=================================================================
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
'
' About References
' Reference to ebrowser.dll (checkin and setting up incl setting
TrustVBProject)
'
'when the program survives previous call then apparently there is no broken
references
VB_References_OK = True
End Function
'check if all broken reference are now cleared an not any broken references
is left
For i = 1 To .References.Count
If .References(i).IsBroken = True Then
MsgBox "Warning, following reference is broken: " &
.References(i).Name _
& " (" & .References(i).FullPath & ")"
CheckReferences = False
End If
Next i
End With
===========================================================================
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Sub CleanUp_RemoveMacros()
Call CleanUp_C(1) ' Removes all macros, etc.
End Sub
' JTK, PROBLEM July 2010, Unprotect password panel remains popped up.
' so temporally till it is fixed I will now disable this function
Exit Sub
'setting is disabled. Now first try to enable the setting and check again
Err.Clear
Call Enable_TrustAccessToVB
i = ThisWorkbook.VBProject.References.Count
If Err = 0 Then
SettingTrustAccessToVB = True 'setting is enabled
SettingChanged = True 'remember that we changed the setting (later
we should set it back)
Else
SettingTrustAccessToVB = False 'setting is disabled
End If
On Error GoTo 0 ' set back to the default error handling in VB
End Function
Sub Enable_TrustAccessToVB()
Dim wsh, str1 'important line, otherwise it will give error in case a
reference is broken
Set wsh = CreateObject("WScript.Shell")
str1 = "HKEY_LOCAL_MACHINE\Software\Microsoft\Office\" & _
Application.Version & "\Excel\Security\AccessVBOM" 'key to modify
wsh.RegWrite str1, 1, "REG_DWORD" 'enable access
End Sub
Sub Disable_TrustAccessToVB()
Dim wsh, str1
Set wsh = CreateObject("WScript.Shell")
str1 = "HKEY_LOCAL_MACHINE\Software\Microsoft\Office\" & _
Application.Version & "\Excel\Security\AccessVBOM" 'key to modify
wsh.RegDelete str1 'Disenable access
End Sub
=========================================================================
REM ***** BASIC *****
Option Explicit
Sub InitializePosSizes()
nXTCPos = cXOffset
nTCWidth = 2000
nDBWidth = 2000
nDBHeight = nDBRefHeight
iReduceWidth = 0
Select Case CurArrangement
Case cColumnarLeft, cLeftJustified
GetLabelDiffHeight(0)
nYTCPos = cYOffset + LABELDIFFHEIGHT
nXDBPos = cXOffset + 3050
nYDBPos = cYOffset
Case cColumnarTop, cTopJustified
nXDBPos = cXOffset
nYTCPos = cYOffset
End Select
End Sub
CurFieldType = com.sun.star.sdbc.DataType.TIME
oTimeModel = CreateUnoService("com.sun.star.form.component.TimeField")
oTimeModel.DataField = CurFieldName
oTimeShape = InsertControl(oGroupShape, oTimeModel, aPoint, aSize)
oTimeShape.Position = GetPoint(nXDBPos + 10 + nDateWidth,nYDBPos)
nTimeWidth = GetPreferredWidth(oTimeModel)
aSize = GetSize(nTimeWidth,nDBHeight)
oTimeShape.SetSize(aSize)
nDBWidth = nDateWidth + nTimeWidth + 10
oGroupShape.Position = aPoint
oGroupShape.Size = GetSize(nDBWidth, nDBHeight)
Set oDBShapeList(i)= oGroupShape
End If
CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
InsertTimeStampShape() = oDBShapeList(i)
End Function
' Note: on all Controls except for the checkbox the Label has to be set
' a bit under the DBControl because its Height is also smaller
Sub GetLabelDiffHeight(Index as Integer)
If (CurArrangement = cLeftJustified) Or (CurArrangement = cColumnarLeft) Then
If Index <= Ubound(FieldMetaValues()) Then
If FieldMetaValues(Index,2) = cCheckBox Then
LabelDiffHeight = 0
Else
LabelDiffHeight = BasicLabelDiffHeight
End If
End If
End If
End Sub
Sub CheckJustifiedPosition()
Dim nLeftDist as Long
Dim nRightDist as Long
Dim oLocDBShape as Object
Dim oLocTextShape as Object
Dim nBaseWidth as Long
nBaseWidth = nFormWidth + cXOffset
nLeftDist = nMaxColRightX - nBaseWidth
nRightDist = nBaseWidth - nXTCPos + cHoriDistance
If nLeftDist < 0.5 * nRightDist and iReduceWidth > 2 Then
' Fieldwidths in the line can be made smaller
AdjustLineWidth(StartA, a, nLeftDist, - 1)
If CurArrangement = cLeftjustified Then
nYDBPos = nMaxRowY + cVertDistance
nYTCPos = nYDBPos + LABELDIFFHEIGHT
nXTCPos = cXOffset
Else
nYTCPos = nMaxRowY + cVertDistance
nYDBPos = nYTCPos + nTCHeight
nXTCPos = cXOffset
nXDBPos = cXOffset
End If
bIsFirstRun = True
StartA = a + 1
Else
Set oLocDBShape = oDBShapeList(a)
Set oLocTextShape = oTCShapeList(a)
If CurArrangement = cLeftJustified Then
If nYDBPos + nDBHeight = nMaxRowY Then
' The last Control was the highest in the row
nYDBPos = nSecMaxRowY + cVertDistance
Else
nYDBPos = nMaxRowY + cVertDistance
End If
nYTCPos = nYDBPos + LABELDIFFHEIGHT
nXDBPos = cXOffset + nTCWidth
oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
oLocDBShape.Position = GetPoint(nXDBPos, nYDBPos)
' PosSizes for the next two Controls
nXTCPos = oLocDBShape.Position.X + oLocDBShape.Size.Width +
cHoriDistance
bIsFirstRun = True
CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight, True)
nXDBPos = nMaxColRightX + cHoriDistance
Else ' cTopJustified
If nYDBPos + nDBHeight = nMaxRowY Then
' The last Control was the highest in the row
nYTCPos = nSecMaxRowY + cVertDistance
Else
nYTCPos = nMaxRowY + cVertDistance
End If
nYDBPos = nYTCPOS + nTCHeight
nXDBPos = cXOffset
nXTCPos = cXOffset
oLocTextShape.Position = GetPoint(cXOffset, nYTCPos)
oLocDBShape.Position = GetPoint(cXOffset, nYDBPos)
bIsFirstRun = True
If nDBWidth > nTCWidth Then
CheckOuterPoints(nXDBPos, nDBWidth, nYDBPos, nDBHeight,
True)
Else
CheckOuterPoints(nXDBPos, nTCWidth, nYDBPos, nDBHeight,
True)
End If
nXTCPos = nMaxColRightX + cHoriDistance
nXDBPos = nXTCPos
End If
AdjustLineWidth(StartA, a-1, nRightDist, 1)
StartA = a
End If
iReduceWidth = 0
End Sub
Sub ControlCaptionstoStandardLayout()
Dim i as Integer
Dim iBorderType as Integer
Dim oCurModel as Object
Dim oStyle as Object
Dim iStandardColor as Long
If CurArrangement <> cTabled Then
oStyle =
oDocument.StyleFamilies.GetByName("ParagraphStyles").GetByName("Standard")
iStandardColor = oStyle.CharColor
For i = 0 To MaxIndex
oCurModel = oTCShapeList(i).GetControl
If i = 0 Then
If oCurModel.TextColor = iStandardColor Then
Exit Sub
End If
End If
oCurModel.TextColor = iStandardColor
Next i
End If
End Sub
Sub GroupShapesTogether()
Dim i as Integer
If CurArrangement <> cTabled Then
For i = 0 To MaxIndex
oGroupShapeList(i) =
CreateUnoService("com.sun.star.drawing.ShapeCollection")
oGroupShapeList(i).Add(oTCShapeList(i))
oGroupShapeList(i).Add(oDBShapeList(i))
oDrawPage.Group(oGroupShapeList(i))
Next i
Else
RemoveNirwanaShapes()
End If
End Sub
===============================================================
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
'
' eBrowser related stuff
'
EbrowserInitialized = False
If Not WorksheetExists(eBrowserSheet) Then Exit Sub
Dim eb_file As String, Sh As String, cl As String, isLoaded
eb_file = arr_settings(HeaderLine8, 83)
If eb_file = "" Or Dir(eb_file) = "" Then Exit Sub
Application.ScreenUpdating = False
Sh = ActiveSheet.Name
cl = ActiveCell.Address
Call sheet_sel(Sh)
Range(cl).Select
Application.ScreenUpdating = True
End Sub
With Sheets(eBrowserSheet).Buttons(1)
.Height = h
End With
With Sheets(eBrowserSheet).OLEObjects(eb_objname)
.Left = L
.Top = 0
.Height = h
.Width = W
End With
End Sub
positionID = get_positionID(Act_Cell_r)
If positionID <> "" Then
Call activate_ebrowser_sheet(Act_Sheet, Act_Cell)
Call FindPosID(positionID)
Call set_size_eb_object(1)
Exit Sub
End If
col = conv_to_number("COL_OBIREF")
If col <> 0 Then
col = arr_settings(HeaderLine2, col) + ListStartCol - 1 'get column
position
ObiRef = Act_SheetIndex & "_" & Cells(Act_Cell_r, col).Value
OneObi = ""
If FindObirefFromImportList(ObiRef, OneObi) = True Then
Call activate_ebrowser_sheet(Act_Sheet, Act_Cell)
Call ShowObirefInEbrowser(OneObi)
Call set_size_eb_object(1)
Else
MsgBox "ReportGenerator debug f1" 'actually this should never occur,
else: find out what the leak is
End If
Else
MsgBox "ReportGenerator debug f2" 'actually this should not occur, else:
find out what the leak is
End If
End Sub
col = conv_to_number("COL_VPO")
If col <> 0 Then
field_vpo_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_vpo_c).Value
If get_positionID <> "" Then Exit Function
End If
col = conv_to_number("COL_NAM")
If col <> 0 Then
field_nam_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_nam_c).Value
If get_positionID <> "" Then Exit Function
End If
col = conv_to_number("COL_IPO")
If col <> 0 Then
field_ipo_c = arr_settings(HeaderLine2, col) + ListStartCol - 1
get_positionID = Cells(RowNr, field_ipo_c).Value
If get_positionID <> "" Then Exit Function
End If
End Function
Call set_size_eb_object(1)
Sheets(eBrowserSheet).Cells(1, 1).Value = "button"
Sheets(eBrowserSheet).Cells(1, 2).Value = Act_Sheet
Sheets(eBrowserSheet).Cells(1, 3).Value = Act_Cell
End Sub
Sub FindPosID(positionID As String)
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthLocateByPosition
positionID, 0
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthShowSidebar (True)
End Sub
Width:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Width -
extra_edge_H, _
Height:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Height -
extra_edge_W)
ebrowser_object.Name = eb_objname
If Err = 0 Then
AddEbrowserObject = True
Else
AddEbrowserObject = False
End If
On Error GoTo 0 ' set back to the default error handling in VB
End Function
extra_edge_H = 6
extra_edge_W = 25
Set ebrowser_object =
ActiveSheet.OLEObjects.Add(classtype:="ebrowser.eBrowser.1", Link:=False, _
DisplayAsIcon:=False, _
Left:=0, Top:=0, _
Width:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Width -
extra_edge_H, _
Height:=ActiveWindow.VisibleRange.SpecialCells(xlCellTypeVisible).Columns.Height -
extra_edge_W)
ebrowser_object.Name = eb_objname
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
End Sub
'
' 'ask for location of eBrowserfile
'
Function get_ebfile() As String
Dim eb_file As String
If WorksheetExists(eBrowserSheet) Then
eb_file = arr_settings(HeaderLine8, 83)
Else
eb_file = ""
End If
If eb_file <> "" And Dir(eb_file) <> "" Then
If MsgBox("Connect to eBrowser-file:" & Chr(10) & Chr(10) & "< " & eb_file
& " >" & Chr(10) & _
Chr(10) & "OK ?" & Chr(10), _
vbQuestion + vbYesNo, "eBrowser link") = vbNo Then
'ask user to select the eBrowser file
eb_file = Application.GetOpenFilename("Select eBrowser file
(*.ebm), *.ebm")
End If
Else
MsgBox "Could not find eBrowser-file <" & eb_file & " >"
'ask user to select the eBrowser file:
eb_file = Application.GetOpenFilename("Select eBrowser file (*.ebm),
*.ebm")
End If
Sheets("import").Visible = True
Sheets("import").Activate
Size_arr_obi = last_row_nr(1, 1) 'call to function last_row_nr()
ReDim arr_obi_sel(1 To Size_arr_obi) As String
Call Fill_arr_obi(arr_obi, Size_arr_obi)
Call Fill_arr_obiRef(arr_ObiRef, Size_arr_obi)
If obi_sel_no = 1 Then 'if one object in set, we can exit because that one obi
will be searched
OneObiField = arr_obi_sel(1)
pos = InStr(OneObiField, "_") ' search by trying to find postion Then, if
not found this means there is only one obi in this field
If pos = 0 Then
FindObirefFromImportList = True
Exit Function
End If
End If
FindObirefFromImportList = True
Application.ScreenUpdating = True
End Function
WriteObisToATextFile = True
End Function
Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthEnableModel (False)
'Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthSetSetVisibility
"ReportGeneratorSet", 1
'Sheets(eBrowserSheet).OLEObjects(eb_objname).Object.mthShowSidebar (False)
End Sub
=================================================================================
Rem Attribute VBA_ModuleType=VBAFormModule
Option VBASupport 1
Private Sub btnOK_Click()
Me.Hide
End Sub
Call ReadSettings(1)
.Sum4.Visible = False
.Sum5.Visible = False
.Label14.Visible = False
.Label15.Visible = False
.ListToSheets.AddItem "(None)"
.Sum1.AddItem "(None)"
.Sum2.AddItem "(None)"
.Sum3.AddItem "(None)"
.Sum4.AddItem "(None)"
.Sum5.AddItem "(None)"
.Sort1.AddItem "(None)"
.Sort2.AddItem "(None)"
.Sort3.AddItem "(None)"
'
'set listfocus to current value
'
Dim SheetDistr_Nr As Integer, SumR1 As Integer, SumR2 As Integer, SumR3 As
Integer, SumR4 As Integer, SumR5 As Integer
Dim SortR1 As Integer, SortR2 As Integer, SortR3 As Integer, sett As String
sett = arr_settings(HeaderLine8, 1)
SheetDistr_Nr = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 2)
SumR1 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 3)
SumR2 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 4)
SumR3 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 78)
SumR4 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 79)
SumR5 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 5)
SortR1 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 6)
SortR2 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 7)
SortR3 = conv_to_number(sett)
.ListToSheets.ListIndex = SheetDistr_Nr
.Sum1.ListIndex = SumR1
.Sum2.ListIndex = SumR2
.Sum3.ListIndex = SumR3
.Sum4.ListIndex = SumR4
.Sum5.ListIndex = SumR5
.Sort1.ListIndex = SortR1
.Sort2.ListIndex = SortR2
.Sort3.ListIndex = SortR3
End With
End Sub
waitpanel.LabelProgress.Width = 0
waitpanel.Show vbModeless 'this will trigger a call to waitpanel_Activate()
PctDone = 0
PctDonePrev = 0
Call WriteSettings(1)
End Sub
===================================================================================
======
Rem Attribute VBA_ModuleType=VBAFormModule
Option VBASupport 1
For ii = 1 To Col_ArraySize
coln = arr_settings(HeaderLine1, ii)
col_nr = arr_settings(HeaderLine2, ii) 'get column position
coln = sett_table(0, col_nr)
desc = sett_table(1, col_nr)
vis = sett_table(2, col_nr)
tag = Trim(sett_table(3, col_nr))
pip = sett_table(4, col_nr)
format = sett_table(5, col_nr)
wid = sett_table(6, col_nr)
sumtxt = sett_table(7, col_nr)
' arr_settings(HeaderLine8, 12
arr_settings(HeaderLine8, 12) = "0" 'default
If CheckBox_total_fields.Value = False And CheckBox_sum_sheet.Value = False
Then
arr_settings(HeaderLine8, 12) = "0"
End If
If CheckBox_total_fields.Value = True And CheckBox_sum_sheet.Value = False Then
arr_settings(HeaderLine8, 12) = "1"
End If
If CheckBox_total_fields.Value = False And CheckBox_sum_sheet.Value = True Then
arr_settings(HeaderLine8, 12) = "2"
End If
If CheckBox_total_fields.Value = True And CheckBox_sum_sheet.Value = True Then
arr_settings(HeaderLine8, 12) = "3"
End If
col_nr = ComboBox_countcol.ListIndex
arr_settings(HeaderLine8, 14) = conv_colnr_to_colname(col_nr)
'report path
arr_settings(HeaderLine8, 90) = TextBox_reppath.Text
Call WriteSettings(1)
Call ReadSettings(1) 'to re-set public settings
Unload Form_Settings
End Sub
Unload Form_Settings
'Form_Settings.Show
End Sub
Sub setup_ListView()
ListView1.ListItems.Clear
ListView1.ColumnHeaders.Clear
ListView1.ColumnHeaders.Add , , "", 20
ListView1.ColumnHeaders.Add , , "Title", 100
ListView1.ColumnHeaders.Add , , "Visibility", 38
ListView1.ColumnHeaders.Add , , "Tag", 80
ListView1.ColumnHeaders.Add , , "Tag from", 63
ListView1.ColumnHeaders.Add , , "Format", 65
ListView1.ColumnHeaders.Add , , "Width", 50
ListView1.ColumnHeaders.Add , , "Sum", 25
ListView1.ColumnHeaders.Add , , "Col_nr", 0
For ii = 1 To Col_ArraySize
coln = arr_settings(HeaderLine1, ii)
col_nr = arr_settings(HeaderLine2, ii) 'get column position
desc = arr_settings(HeaderLine10, ii)
desc = Replace(desc, Chr(10), " ") 'delete <Enter> from string
vis = "Hide"
If arr_settings(HeaderLine3, ii) = "SHOW" Then vis = "Show"
tag = Trim(arr_settings(HeaderLine5, ii))
If LCase(arr_settings(HeaderLine7, ii)) = "sum" Then
sumtxt = "Yes"
Else
sumtxt = "No"
End If
Next ii
Next iCounter
End Sub
Sub edit_row()
Button_EditRow.Locked = True
Button_EditRow.Enabled = False
'Set ListView1.SelectedItem = ListView1.ListItems(3)
Load Form_settings2
Form_settings2.Show
End Sub
'=======================================================================
' SETTINGS-SHEET LAYOUT
'
Sub setup_layout()
ComboBox_layout.AddItem "LAYOUT1"
For Each WorkSh In ActiveWorkbook.Worksheets
If (UCase(Left(WorkSh.Name, 6)) = "LAYOUT") Then
ComboBox_layout.AddItem WorkSh.Name
End If
Next
'
'set listfocus to current value
'
Dim sett As String, nr As Integer, item As String
nr = 0
sett = arr_settings(HeaderLine8, 8)
With Me.ComboBox_layout
.ListIndex = 0 'default
For i = 0 To .ListCount - 1
item = .List(i)
If item = sett Then
.ListIndex = nr
End If
nr = nr + 1
Next i
End With
TextBox_sheet_hlines.Text = arr_settings(HeaderLine8, 9)
TextBox_sheet_hcolumns.Text = arr_settings(HeaderLine8, 10)
End Sub
CheckBox_hidetitelrow.Locked = True
CheckBox_hidetitelrow.Enabled = False
CheckBox_colwidth_via_sheet.Locked = True
CheckBox_colwidth_via_sheet.Enabled = False
Label5.Enabled = False
Label6.Enabled = False
Else
TextBox_sheet_hlines.Text = arr_settings(HeaderLine8, 9)
TextBox_sheet_hlines.Locked = False
TextBox_sheet_hlines.BackColor = &H80000005
TextBox_sheet_hcolumns.Text = arr_settings(HeaderLine8, 10)
TextBox_sheet_hcolumns.Locked = False
TextBox_sheet_hcolumns.BackColor = &H80000005
CheckBox_hidetitelrow.Locked = False
CheckBox_hidetitelrow.Enabled = True
CheckBox_colwidth_via_sheet.Locked = False
CheckBox_colwidth_via_sheet.Enabled = True
Label5.Enabled = True
Label6.Enabled = True
End If
End Sub
'=======================================================================
' SETTINGS-SHEET Miscellaneous
'
Sub setup_miscellaneous()
TextBox_seperator.Locked = True
TextBox_columns.Locked = True
DirButton.Locked = True
Else
Label36.Enabled = True
TextBox_seperator.Enabled = True
Label37.Enabled = True
TextBox_columns.Enabled = True
Label38.Enabled = True
DirButton.Enabled = True
TextBox_seperator.Locked = False
TextBox_columns.Locked = False
DirButton.Locked = False
End If
TextBox_seperator.Locked = True
TextBox_columns.Locked = True
DirButton.Locked = True
Else
Label36.Enabled = True
TextBox_seperator.Enabled = True
Label37.Enabled = True
TextBox_columns.Enabled = True
Label38.Enabled = True
DirButton.Enabled = True
TextBox_seperator.Locked = False
TextBox_columns.Locked = False
DirButton.Locked = False
End If
End Sub
End Sub
Unload Form_settings2
End Sub
End Sub
col_nr = .ListItems(row).SubItems(8)
End With
ComboBox_TagFrom.AddItem tagfrom_options(1, 1)
ComboBox_TagFrom.AddItem tagfrom_options(2, 1)
ComboBox_TagFrom.AddItem tagfrom_options(3, 1)
ComboBox_TagFrom.AddItem tagfrom_options(4, 1)
ComboBox_TagFrom.AddItem tagfrom_options(5, 1)
ComboBox_TagFrom.AddItem tagfrom_options(6, 1)
ComboBox_TagFrom.ListIndex = TagFrom
ComboBox_sum.AddItem "No"
ComboBox_sum.AddItem "Yes"
ComboBox_sum.ListIndex = sumnr
ComboBox_width.AddItem "Autofit"
ComboBox_width.AddItem "Fixed"
ComboBox_width.AddItem "Min."
ComboBox_width.AddItem "Max."
ComboBox_width.ListIndex = widnr
If widnr = 0 Then
TextBox_width.Locked = True
TextBox_width.BackColor = &H80000011
CommandButton_width.Enabled = False
Else
TextBox_width.Locked = False
TextBox_width.BackColor = &H80000005
CommandButton_width.Enabled = True
End If
ComboBox_Format.AddItem "String"
ComboBox_Format.AddItem "Number, 0 Dec."
ComboBox_Format.AddItem "Number, 1 Dec."
ComboBox_Format.AddItem "Number, 2 Dec."
ComboBox_Format.AddItem "Number, 3 Dec."
ComboBox_Format.AddItem "Date"
ComboBox_Format.AddItem "formula"
ComboBox_Format.ListIndex = formatnr
Call ini_formula
End Sub
Private Sub ini_formula()
If ComboBox_Format.ListIndex = 6 Then ' Choosen format is "formula"
Frame1.Visible = False
TextBox_Formula.Visible = True
Label33.Visible = True
ValidateFormulaButton.Visible = True
TextBoxHelpFormula.Visible = True
Else
Frame1.Visible = True
TextBox_Formula.Visible = False
Label33.Visible = False
ValidateFormulaButton.Visible = False
TextBoxHelpFormula.Visible = False
End If
End Sub
End Sub
' when tag begins with a "=" then put a space in front of it to avoid
interpretation as formula
If Left(t1, 1) = "=" Then t1 = " " & t1
If Left(t2, 1) = "=" Then t2 = " " & t2
If Left(t3, 1) = "=" Then t3 = " " & t3
If Left(t4, 1) = "=" Then t4 = " " & t4
If Left(t5, 1) = "=" Then t5 = " " & t5
If Left(t6, 1) = "=" Then t6 = " " & t6
If Left(t7, 1) = "=" Then t7 = " " & t7
If Left(t8, 1) = "=" Then t8 = " " & t8
If Left(t9, 1) = "=" Then t9 = " " & t9
If Left(t10, 1) = "=" Then t10 = " " & t10
tag = t1
If t1 = "" Then
Exit Sub
Else
If t2 <> "" Then
tag = tag & "+" & t2
If t3 <> "" Then
tag = tag & "+" & t3
If t4 <> "" Then
tag = tag & "+" & t4
If t5 <> "" Then
tag = tag & "+" & t5
If t6 <> "" Then
tag = tag & "+" & t6
If t7 <> "" Then
tag = tag & "+" & t7
If t8 <> "" Then
tag = tag & "+" & t8
End If
End If
End If
End If
End If
End If
End If
End If
If t9 <> "" Then
tag = tag & "~" & t9
If t10 <> "" Then tag = tag & "+" & t10
End If
'Fix: if first char is ' then put space before it otherwise excel will
' skip this when putting value to a cell.
If Left(tag, 1) = "'" Then tag = " " & tag
End Sub
ErrorHandlingLabel:
MsgBox "Warning, formula is NOT valid: " & tagstring
Range("HH1").Value = ""
On Error GoTo 0 ' set back to the default error handling in VB
End Sub
============================================================================
Rem Attribute VBA_ModuleType=VBAFormModule
Option VBASupport 1
Dim ListContent(1 To 91) As Variant
End Sub
' fill ColHideShow() array retrieved from current sheet and setup panel
For iCounter = 1 To Col_ArraySize
item = ColTitel(iCounter)
If Columns(iCounter + ListStartCol - 1).EntireColumn.Hidden = True Then
Me.LabelHiddenCol.AddItem item
Else
Me.LabelVisibleCol.AddItem item
End If
Next iCounter
End Sub
Application.ScreenUpdating = False
Me.Hide
Dim WorkSh As Worksheet
Dim remembered_activesheetname As String, remembered_activecell As String
remembered_activesheetname = ActiveSheet.Name
remembered_activecell = ActiveCell.Address
'
'scan which items are selected to be shown, and fill array
'
With Me.LabelHiddenCol
For i = 0 To .ListCount - 1
c_nr = c_nr + 1
item = .List(i)
For iCounter = 1 To Col_ArraySize
titel_desc = arr_settings(HeaderLine10, iCounter)
titel_desc = Replace(titel_desc, Chr(10), " ") 'delete <Enter> from
string
If item = titel_desc Then
arr_settings(HeaderLine2, iCounter) = c_nr 'set new column
number
arr_settings(HeaderLine3, iCounter) = "HIDE" 'set Show/Hide
End If
Next iCounter
Next i
End With
' Declaration
Dim nr_of_sheets As Long
nr_of_sheets = Sheets.Count
ReDim TotalFields(1 To nr_of_sheets, 1 To 12) As Variant
'
' re-arrange complete sheet according new position and show/hide
'
Call ReArrange(LastRowColA, LastColRow1, SheetNr)
End If
Next
Call WriteSettings(0)
'HIDE sheets
Call HideSheets(1)
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Application.ScreenUpdating = True
Me.Hide
Unload Form_ShowColumns
End Sub
End Sub
'deselect first all items in visible column ( to see clearly which one is
added)
With Me.LabelVisibleCol
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
.Selected(i) = False
End If
Next i
End With
With Me.LabelHiddenCol
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
.Selected(i) = False
item = .List(i)
Me.LabelVisibleCol.AddItem item
Me.LabelVisibleCol.Selected(Me.LabelVisibleCol.ListCount - 1) =
True
.RemoveItem i
End If
Next i
End With
Application.ScreenUpdating = True
End Sub
Dim i As Integer
Application.ScreenUpdating = False
'deselect first all items in visible column ( to see clearly which one is
added)
With Me.LabelHiddenCol
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
.Selected(i) = False
End If
Next i
End With
With Me.LabelVisibleCol
'li = .ListIndex
For i = .ListCount - 1 To 0 Step -1
If .Selected(i) Then
item = .List(i)
Me.LabelHiddenCol.AddItem item
Me.LabelHiddenCol.Selected(Me.LabelHiddenCol.ListCount - 1) = True
.RemoveItem i
End If
Next i
Dim i As Integer
With Me.LabelVisibleCol
If .ListCount > 0 Then
Application.ScreenUpdating = False
For i = 0 To .ListCount - 1
Me.LabelHiddenCol.AddItem .List(i)
Next i
.Clear
Application.ScreenUpdating = True
End If
End With
End Sub
pos = LabelVisibleCol.ListCount - 1
leaveAlone = False
If LabelVisibleCol.Selected(i) Then
If i = pos Then
leaveAlone = True
End If
pos = pos - 1
If Not leaveAlone Then
Temp = LabelVisibleCol.List(i + 1)
LabelVisibleCol.List(i + 1) = LabelVisibleCol.List(i)
LabelVisibleCol.List(i) = Temp
LabelVisibleCol.ListIndex = i + 1
LabelVisibleCol.Selected(i) = False
LabelVisibleCol.Selected(i + 1) = True
End If
End If
Next
End Sub
pos = 0
For i = 0 To LabelVisibleCol.ListCount - 1
leaveAlone = False
If LabelVisibleCol.Selected(i) Then
If i = pos Then
leaveAlone = True
End If
pos = pos + 1
'
' Just before writing the array to the sheet we now (re-)arrange the order of
the columns
'
Dim ColNr_old As Integer, ColNr_new As Integer
For iCol = 1 To nr_of_cols
ColNr_old = ColPos(iCol)
ColNr_new = arr_settings(HeaderLine2, iCol)
'
'write back to the sheet the array arr_outB
'
Call SetColFormat(1) 'set format correct otherwise value might get mutilated
(0011 becomes 11)
Range(Cells(ListStartLine, ListStartCol), Cells(LastRowColA,
LastColRow1)).Value = arr_outB
'Call Rounding(LastRowColA)
Cells(1, 1).Select 'just select "A1" in order to get active cel to so far down
End Sub
===================================================================================
========
Rem Attribute VBA_ModuleType=VBAFormModule
Option VBASupport 1
Private Sub UserForm_activate()
arr_settings(HeaderLine8, 1) = conv_colnr_to_colname(SheetDistr_Nr)
arr_settings(HeaderLine8, 2) = conv_colnr_to_colname(SumR1)
arr_settings(HeaderLine8, 3) = conv_colnr_to_colname(SumR2)
arr_settings(HeaderLine8, 4) = conv_colnr_to_colname(SumR3)
arr_settings(HeaderLine8, 5) = conv_colnr_to_colname(SortR1)
arr_settings(HeaderLine8, 6) = conv_colnr_to_colname(SortR2)
arr_settings(HeaderLine8, 7) = conv_colnr_to_colname(SortR3)
arr_settings(HeaderLine8, 78) = conv_colnr_to_colname(SumR4)
arr_settings(HeaderLine8, 79) = conv_colnr_to_colname(SumR5)
Call WriteSettings(0)
Call Progress(1)
'wait 1 sec. to give user enough time to see that 100% is reached.
'Application.Wait (Now + TimeValue("00:00:01")) 'wait 1 sec.
Unload waitpanel
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Application.ScreenUpdating = True
End If
End Sub
===================================================================================
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Sub Macro_Main_Import()
'
'initialize
'
If NotAllowedToStartMacroFromHere(True) Then Exit Sub
StartedFromListControl = False
Call init(1)
' Define Importfile-name: same as current workbook, only without the extension
".sum"
Dim ThisWorkbookPath As String, ThisWorkbookName As String, Importfile As
String
ThisWorkbookPath = ThisWorkbook.Path
ThisWorkbookName = ThisWorkbook.Name
ThisWorkbookName = Left(ThisWorkbookName, Len(ThisWorkbookName) - 4) 'cut off
the extension ".xls"
Importfile = ThisWorkbookPath & "\" & ThisWorkbookName & ".sum"
'check if importfile exists:
If Dir(Importfile) = "" Then
MsgBox "Warning, Could not find file " & Importfile
Exit Sub
End If
Application.ScreenUpdating = False
Application.Visible = False 'hide excel application, so only wait-panel is
visible
waitpanel.LabelProgress.Width = 0
Load waitpanel
waitpanel.Show vbModeless
Call Progress(0.01)
Call Progress(0.03)
'
'Copy content of this imported excel workbook into current sheet and delete
that workbook
'
Dim Importfile_excel As String
Importfile_excel = ThisWorkbookName & ".sum"
Application.DisplayAlerts = False 'to avoid message about clipboard when
coping
Windows(Importfile_excel).Activate 'activate imported excel workbook
Cells.Select 'select whole sheet
Selection.Copy 'copy whole sheet to clipboard
Windows(ThisWorkbook.Name).Activate 'activate current workbook
If Not WorksheetExists("import") Then
Sheets.Add 'Add new sheet
ActiveSheet.Name = "import" 'Rename new sheet
End If
Sheets("import").Select 'select the sheet with the name "import"
Cells.Select 'select whole sheet
ActiveSheet.Paste 'paste content of clipboard to the sheet
Windows(Importfile_excel).Activate 'activate imported excel workbook
'
Call Progress(0.04)
Application.CutCopyMode = False 'Clear Clipboard. VERY GOOD LINE: it will
fasten up
' following SAVE/CLOSE very much (no time
instead of 2 sec)
ActiveWindow.Close savechanges:=0 'close imported excel workbook
Call Progress(0.05)
Application.DisplayAlerts = True 'set original value back ("True")
'
'setup sheets; distribute import sheets to the differen sheets and setup layout
'
Dim SheetDistr_Nr As Integer, SumR1 As Integer, SumR2 As Integer, SumR3 As
Integer, SumR4 As Integer
Dim SumR5 As Integer, SortR1 As Integer, SortR2 As Integer, SortR3 As Integer,
sett As String
sett = arr_settings(HeaderLine8, 1)
SheetDistr_Nr = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 2)
SumR1 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 3)
SumR2 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 4)
SumR3 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 78)
SumR4 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 79)
SumR5 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 5)
SortR1 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 6)
SortR2 = conv_to_number(sett)
sett = arr_settings(HeaderLine8, 7)
SortR3 = conv_to_number(sett)
End If
'SAVE
Application.CutCopyMode = False 'Clear Clipboard. VERY GOOD LINE: it
will fasten up
' following SAVE/CLOSE vermy much (no
time instead of 2 sec)
ActiveWorkbook.Save
Application.CutCopyMode = True ' set value back to orginal value
Call Progress(1)
'wait 1 sec. to give user enough time to see that 100% is reached.
'Application.Wait (Now + TimeValue("00:00:01")) 'wait 1 sec.
Unload waitpanel
End If
Else
Application.WindowState = xlMaximized 'Maxmize excel window
Application.ScreenUpdating = True
Application.Visible = True
End If
End Sub
End Sub
'setup lautout of import sheet (much layout is copied to other sheets form
there)
If (setup_importsheet) Then Call Layout_of_import_sheet
PctDone = 0.25
Call Progress(PctDone) 'set how much procent is done in pogress-bar
End Sub
'un-hide sheet "import", because we only can delete the old sheets when
'there is at least one sheet left visible
Sheets("import").Visible = True
If DistrColNr = 0 Then
'selected DistrColNr is 0 (= None)
Rows(2 & ":" & LastRowColA).Select
Range("A" & 2 & ":" & Column2Char(LastColRow1) & LastRowColA).Select
Selection.Copy
Sheets.Add 'Add new sheet
ActiveSheet.Name = "All" 'Rename new sheet
Range(Column2Char(ListStartCol) & ListStartLine).Select
ActiveSheet.Paste
Call Progress(0.25)
'exit Subroutine:
Exit Sub
End If
PctDone = 0.09
Call Progress(PctDone)
'First Sort that column in sheet "import" in order to find the unique values
Dim SortCelValue As String, SortCelValuePrev As String
Rows("2:" & LastRowColA).Select
Selection.Sort Key1:=Cells(2, DistrColNr), Order1:=xlAscending,
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
End Sub
'get rid of strange character in sheetname which excel cannot handle when
renaming sheet
Dim i As Long
For i = 1 To Len(sheet_name)
Select Case Mid$(sheet_name, i, 1)
Case "?"
Mid$(sheet_name, i, 1) = "."
Case "/"
Mid$(sheet_name, i, 1) = "."
Case "\"
Mid$(sheet_name, i, 1) = "."
Case "*"
Mid$(sheet_name, i, 1) = "."
Case "["
Mid$(sheet_name, i, 1) = "."
Case "]"
Mid$(sheet_name, i, 1) = "."
Case Else
End Select
Next
If WorksheetExists(sheet_name) Then
MsgBox ("Warning, Could not add sheet <" & sheet_name & "> because this
sheet already exists.")
sheet_name = sheet_name & "_WARNING_"
End If
ActiveSheet.Name = sheet_name 'Rename new sheet
End Sub
Call Progress(0.06)
'
' Layout rows: make left & right -borders of every row thick
'
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Call Progress(0.07)
End With
Next cel
End If
'
' Layout title row: make bold text, filling, and thick outer Border
'
Range(Cells(1, 1), Cells(1, LastColRow1)).Select
Selection.RowHeight = 35
'bold text:
For Each cel In Selection
cel.Font.Bold = True
Next cel
' filling:
With Selection.Interior
.ColorIndex = 15 'light-gray
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
End With
Call Progress(0.08)
End Sub
'
'Read settings
'
layoutsheet = UCase(arr_settings(HeaderLine8, 8))
If LCase(arr_settings(HeaderLine8, 11)) = "columnwidth_via_layoutsheet" Then
columnwidth_via_layoutsheet = True
Else
columnwidth_via_layoutsheet = False
End If
'
'copy headerlines of the layoutsheet to current sheet (content and width)
'
If WorksheetExists(layoutsheet) Then
Sheets(layoutsheet).Visible = True
Call sheet_sel(layoutsheet) 'select the sheet with that name
'
'Titel-labels: description
'
Range(Cells(Titel_row_nr, ListStartCol), Cells(Titel_row_nr,
LastColRow1)).Value = Titel_row
'
' Titel-labels: make bold text, filling, and thick outer Border
'
Range(Cells(Titel_row_nr, ListStartCol), Cells(Titel_row_nr,
LastColRow1)).Select
Selection.RowHeight = 35
'bold text:
For Each cel In Selection
cel.Font.Bold = True
Next cel
OuterBorderThick
End If
'Titel-row: HIDE
If hidetitelrow = True Then
Rows(Titel_row_nr).Select
Selection.EntireRow.Hidden = True
End If
'
' Select layoutsheet additional sheet definitions
'
Select Case layoutsheet
Case "LAYOUT1"
Call Layout1(sheetname, LastRowColA, LastColRow1, quick) 'default
layout
Case "LAYOUT2"
Call Layout2(sheetname, LastRowColA, LastColRow1, quick)
Case Else
Call Layout1(sheetname, LastRowColA, LastColRow1, quick) 'default
layout
End Select
Call set_named_cell(sheetname)
'
' Add total fields (like total mass total length, total COG)
' (also activates that sheet
'
Call addtotalfields(LastRowColA, LastColRow1, SheetNr)
'
' Column width
'
If columnwidth_via_layoutsheet = False Then
Call Columns_Width(Titel_row_nr, LastRowColA, LastColRow1)
End If
'
'DECIMALS presenting ( and also assign formula )
'
Call Rounding(LastRowColA)
'
'HIDE / SHOW the columns
'
Call Columns_HideShow(LastRowColA, LastColRow1)
'Fill_counter_column
Dim counter As Long, sett As String, cc As Integer
sett = arr_settings(HeaderLine8, 14)
counter_col_nr = conv_to_number(sett)
If counter_col_nr > 0 Then
cc = arr_settings(HeaderLine2, counter_col_nr) 'get column position
cc = cc + ListStartCol - 1
counter = 0
For rr = ListStartLine To LastRowColA
counter = counter + 1
Cells(rr, cc).Value = counter
Next rr
End If
Range("A1").Select
End Sub
'retrieve Projname from excel-filename (so, after "_" and without extension)
Dim projectname As String, UnderScorePosition As Integer, pos As Integer
projectname = ThisWorkbook.Name
UnderScorePosition = InStr(1, projectname, "_") 'get postion of "_"
If UnderScorePosition > 0 Then
pos = UnderScorePosition + 1 'begin after "_"
projectname = Mid(projectname, pos, Len(projectname) - (pos - 1) - 4)
End If
End Sub
Sub Layout2(sheetname As Worksheet, LastRowColA As Long, LastColRow1 As Long, quick
As Boolean)
'
' BORDERS: Outer border is double line and inner cells normal line
'
Range(Cells(ListStartLine, ListStartCol), Cells(LastRowColA,
LastColRow1)).Select
Call InnerNormal_OuterDouble_Border(1)
'
'BORDERS: column 16 should be total empty only left and right line is double
line
'
Dim sel_col_nr As Integer
sel_col_nr = ListStartCol + 16 - 1
Range(Cells(ListStartLine, sel_col_nr), Cells(LastRowColA, sel_col_nr)).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
With Selection.Borders(xlEdgeRight)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
'
'BORDERS: column 17 should be total empty only left and right line is double
line
'
sel_col_nr = ListStartCol + 17 - 1
Range(Cells(ListStartLine, sel_col_nr), Cells(LastRowColA, sel_col_nr)).Select
With Selection.Borders(xlEdgeRight)
.LineStyle = xlDouble
.Weight = xlThick
.ColorIndex = xlAutomatic
End With
'printpreview
With ActiveSheet.PageSetup
.Orientation = xlLandscape
.Zoom = 43
.LeftMargin = Application.InchesToPoints(0.3)
.RightMargin = Application.InchesToPoints(0.3)
End With
'zoom
ActiveWindow.Zoom = 75
End Sub
End Sub
'
'Copy first lines of this imported excelWorkbook into curr sheet,& delete that
workbook
'
Dim Importfile_excel As String
Importfile_excel = ThisWorkbookName & ".sum"
Application.DisplayAlerts = False 'to avoid message about clipboard when
coping
Windows(Importfile_excel).Activate 'activate imported excel workbook
Rows("1:" & HeaderLines).Select 'select the header (which is the first
few lines)
Selection.Copy 'copy whole sheet to clipboard
Windows(ThisWorkbook.Name).Activate 'activate current workbook
If Not WorksheetExists("settings") Then
Sheets.Add 'Add new sheet
ActiveSheet.Name = "settings" 'Rename new sheet
End If
Sheets("settings").Select 'select the sheet with the name
"settings"
Rows(QueryLines + 1 & ":" & QueryLines + HeaderLines).Select
ActiveSheet.Paste 'paste content of clipboard to the sheet
Call ReadSettings(0)
End Sub
Sheets("settings").Visible = True
Sheets("settings").Select
Call get_number_of_query_lines(1)
'only for compat reason add new columns: (because they migh miss when
rrp-file is form old version)
If Trim(arr_settings(HeaderLine1, COL_CUST41)) = "" Then
arr_settings(HeaderLine1, COL_CUST41) = "COL_CUST41"
arr_settings(HeaderLine2, COL_CUST41) = first_free_pos()
arr_settings(HeaderLine3, COL_CUST41) = "HIDE"
arr_settings(HeaderLine4, COL_CUST41) = "string"
End If
If Trim(arr_settings(HeaderLine1, COL_CUST42)) = "" Then
arr_settings(HeaderLine1, COL_CUST42) = "COL_CUST42"
arr_settings(HeaderLine2, COL_CUST42) = first_free_pos()
arr_settings(HeaderLine3, COL_CUST42) = "HIDE"
arr_settings(HeaderLine4, COL_CUST42) = "string"
End If
If Trim(arr_settings(HeaderLine1, COL_OBIREF)) = "" Then
arr_settings(HeaderLine1, COL_OBIREF) = "COL_OBIREF"
arr_settings(HeaderLine2, COL_OBIREF) = first_free_pos()
arr_settings(HeaderLine3, COL_OBIREF) = "HIDE"
arr_settings(HeaderLine4, COL_OBIREF) = "string"
End If
' Read the FORMAT-setting of the columns and store it in a public array
Call GetColFormat(1)
Sheets("settings").Visible = False
End Sub
Sub WriteSettings(SwitchBackToSheet As String)
If Not WorksheetExists("settings") Then
Exit Sub
End If
Sheets("settings").Visible = True
Sheets("settings").Select
'read in whole settings-sheet into an array
'Dim arr_settings As Variant 'MUST be variant (is already declared as public)
Sheets("settings").Visible = False
If SwitchBackToSheet = "1" Then
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Application.ScreenUpdating = True
End If
End Sub
Application.ScreenUpdating = True
End Sub
Sub PresentDecimals(SelColumn As Integer, LastRowColA As Long, NrOfDecimals As
Integer)
Range(Cells(ListStartLine, SelColumn), Cells(LastRowColA, SelColumn)).Select
If NrOfDecimals = 0 Then Selection.NumberFormat = "0"
If NrOfDecimals = 1 Then Selection.NumberFormat = "0.0"
If NrOfDecimals = 2 Then Selection.NumberFormat = "0.00"
If NrOfDecimals = 3 Then Selection.NumberFormat = "0.000"
End Sub
Function Column2Char(ColumnNumber As Integer) As String
If ColumnNumber > 26 Then
End Sub
End Sub
'
'DECIMALS presenting ( and also call to assign formula)
'
Dim col_nr As Integer, declaration As String, decimals As String, col_nr_unit
As Integer
Dim celformat As String, row As Long, unit As String, pcs As String, TheFormula
As String
End If
If declaration = "formula" Then
col_nr = arr_settings(HeaderLine2, iCounter) 'get column position
col_nr = col_nr + ListStartCol - 1
TheFormula = "=" & arr_settings(HeaderLine5, iCounter)
TheFormula = Replace(TheFormula, "[R]", ListStartLine)
If TheFormula <> "" Then Call AssignFormula(col_nr, LastRowColA,
TheFormula)
End If
Next iCounter
End Sub
Sub AssignFormula(SelColumn As Integer, LastRowColA As Long, TheFormula As String)
On Error GoTo ErrorHandlingLabel
Range(Cells(ListStartLine, SelColumn), Cells(LastRowColA, SelColumn)).Select
Range(Cells(ListStartLine, SelColumn), Cells(LastRowColA, SelColumn)).Formula =
TheFormula
On Error GoTo 0 ' set back to the default error handling in VB
Exit Sub
ErrorHandlingLabel:
MsgBox "Warning the following formula has a problem (so check via report
control the formula) : " & TheFormula
On Error GoTo 0 ' set back to the default error handling in VB
End Sub
'col width
If MinMax = "" Then
Columns(col_nr).ColumnWidth = width_str
End If
End If
Next iCounter
End Sub
get_obi_from_pipefile = ""
If InStr(guid, "-") <= 0 Then
Exit Function
End If
End Function
get_obi = obi
End Function
End If
End Function
'Select sheet
Sub sheet_sel(sh_name As String)
If sh_name <> ActiveSheet.Name Then
If WorksheetExists(sh_name) Then
If Sheets(sh_name).Visible = True Then Sheets(sh_name).Select
End If
End If
End Sub
End Sub
=================================================================================
Rem Attribute VBA_ModuleType=VBAModule
Option VBASupport 1
Option Explicit
'
' creates a new menu.
'
Dim cbMenu As CommandBarControl, cbSubMenu As CommandBarControl
End With
If (CheckServicePack(2)) Then
' add menuitem to menu
With cbMenu.Controls.Add(msoControlButton, 1, , , True)
.Caption = "&eBrowser link"
.OnAction = ThisWorkbook.Name & "!setup_eBrowser_link"
.Style = msoButtonIconAndCaption
.FaceId = 1577
.BeginGroup = True
End With
End If
'tip:
'instead of .FaceId = 463 you can also use your own facID's by replacing it with:
'Sheet1.Shapes("Pic1").Copy
'.PasteFace
Application.ScreenUpdating = False
Call ReadSettings(0)
End If
Next
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Call RemoveMenu
Call EbrowserInitialize(False, False) 'check if eBrowser is initialized
Call CleanUp_C(1) ' Removes all macros, etc.
Application.ScreenUpdating = True
' Special treatment for ebrowsersheet while earlier it was crashing during
deletion in previous block ( probably somehow related to the activeX object)
' And also below lines should be done at the end because after this some
function somehow do not work anymore like: Application.ActiveWorkbook.Name
If WorksheetExists("eBrowser") Then
If EbrowserInitialized = False Then ' skip deleting when its active
because otherwise excel crashes
Application.DisplayAlerts = False
' Sheets("eBrowser").Delete ' does not yet work, it crashes because
eBrowser object is still somehow active. Lic even remains active till complete
excel is closed
Application.DisplayAlerts = True
End If
End If
End Sub
Sub Macro_ExportToCSV()
Call ExportToCSV(True)
End Sub
Application.ScreenUpdating = False
Call ReadSettings(0)
Call ExportToCSV_core(with_message)
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Application.ScreenUpdating = True
End Sub
define_CSV_columns = ""
End Function
Sub Macro_ListControl()
Call init(1)
If NotAllowedToStartMacroFromHere(True) Then Exit Sub
Form_ListControl.Show
End Sub
Sub Macro_Form_ShowColumns()
Call init(1)
If NotAllowedToStartMacroFromHere(True) Then Exit Sub
If (filtersheets(ActiveSheet.Name) = True) Then
MsgBox "Not possible to start this function from sheet '" &
ActiveSheet.Name & "'" & _
Chr(10) & " ( please first select another sheet to start this
function )"
Exit Sub
End If
Form_ShowColumns.Show
End Sub
End Function
Sub Macro_WriteSettingsFile()
Call init(1)
If NotAllowedToStartMacroFromHere(True) Then Exit Sub
If Not WorksheetExists("settings") Then Exit Sub
remembered_activesheetname = ActiveSheet.Name
remembered_activecell = ActiveCell.Address
Call ReadSettings(1)
Application.ScreenUpdating = False
Sheets("settings").Visible = True
Sheets("settings").Select
Close #vFileNum
Call sheet_sel(remembered_activesheetname)
Range(remembered_activecell).Select
Sheets("settings").Visible = False
Application.ScreenUpdating = True
End Sub
If i > 0 Then
Do While ((szCut <> szPathSep) And (i > 0))
szCut = Mid$(FullPath, i, 1)
If szCut = szPathSep Then
szPath = Left$(FullPath, i)
szFile = Right$(FullPath, Len(FullPath) - i)
End If
i = i - 1
Loop
End Function
===================================================================================