06-45.598553 contact@hpvl.nl

VBA biblio

Classes

t
Class from Table
Option Explicit

'properties
Public Pr_Line As Integer
Public Pr_Key As String
Public Pr_Group As String
Public Pr_ERPId As String
Public Pr_LocalName As String
Public Pr_OneStreamId As String
Public Pr_Type As String
Public Pr_DV As Boolean 'Departementaal Vertrouwelijk True/False
Public Pr_CalcHrsTar As Boolean

'methods
Sub Retrieve(ReadLine As Double)

Me.Pr_Line = ReadLine
Me.Pr_Key = wsProjects.[tblProjects[Proj_Key]].Rows(ReadLine).Value
Me.Pr_Group = wsProjects.[tblProjects[Proj_Group]].Rows(ReadLine).Value
Me.Pr_ERPId = wsProjects.[tblProjects[Proj_ERPID]].Rows(ReadLine).Value
Me.Pr_LocalName = wsProjects.[tblProjects[Proj_Local_Name]].Rows(ReadLine).Value
Me.Pr_OneStreamId = wsProjects.[tblProjects[Proj_OnestreamID]].Rows(ReadLine).Value
Me.Pr_Type = wsProjects.[tblProjects[Proj_Type]].Rows(ReadLine).Value
Me.Pr_DV = wsProjects.[tblProjects[Proj_DV]].Rows(ReadLine).Value
Me.Pr_CalcHrsTar = wsProjects.[tblProjects[Calc_Hours_Tariff]].Rows(ReadLine).Value

End Sub

 

 

Pivots

t
Create a Pivot Table 1

 

public wbTest as workbook
public wsTable as worksheet
public wsPiv as worksheet

Sub CreatePivotTable
wbTest.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=wsTable.ListObjects("tblTest"), Version:=6).CreatePivotTable TableDestination:=wsPiv.[a3], TableName:="PivotTest", DefaultVersion:=6

With wsPiv.PivotTables("PivotTest").PivotFields("MyField1")
   .Orientation = xlPageField
    .Position = 1
End With

With ActiveSheet.PivotTables("PivotTest").PivotFields("MyField2")
    .Orientation = xlRowField
   .Position = 1
End With

End Sub

 

Create a Pivot Table 2
Sub CreatePivotTable()
'PURPOSE: Creates a brand new Pivot table on a new worksheet from data in the ActiveSheet
Dim sht As Worksheet
Dim pvtCache As PivotCache
Dim pvt As PivotTable
Dim StartPvt As String
Dim SrcData As String

'Determine the data range you want to pivot
   SrcData = ActiveSheet.Name & "!" & Range("A1:R100").Address(ReferenceStyle:=xlR1C1)

'Create a new worksheet
   Set sht = Sheets.Add

'Where do you want Pivot Table to start?
   StartPvt = sht.Name & "!" & sht.Range("A3").Address(ReferenceStyle:=xlR1C1)

'Create Pivot Cache from Source Data
   Set pvtCache = ActiveWorkbook.PivotCaches.Create( _
   SourceType:=xlDatabase, _
   SourceData:=SrcData)

'Create Pivot table from Pivot Cache
   Set pvt = pvtCache.CreatePivotTable(TableDestination:=StartPvt, TableName:="PivotTable1")

End Sub

 

Create multiple Pivot from one Cache
Option Explicit

Sub CreateMultiplePivotTables()

    'set the data for the source range
    Dim source_range As Range
    Set source_range = ActiveSheet.Range("A1").CurrentRegion

    'create the pivot cache
    Dim pivot_cache As PivotCache
    Set pivot_cache = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=source_range)

    Dim current_sheet As Worksheet
    Dim current_pivottable As PivotTable

    'create a new worksheet for the first pivot table
    Set current_sheet = Worksheets.Add

    'create first pivot table
    Set current_pivottable = current_sheet.PivotTables.Add(PivotCache:=pivot_cache, TableDestination:=current_sheet.Range("A1"), TableName:="PivotTable1")

    'build the first pivot table
    With current_pivottable
        'etc
        '
        '
    End With

    'create another new worksheet for the second pivot table
    Set current_sheet = Worksheets.Add

    'create second pivot table
    Set current_pivottable = current_sheet.PivotTables.Add(PivotCache:=pivot_cache, TableDestination:=current_sheet.Range("A1"), TableName:="PivotTable2")

    'build the second pivot table
    With current_pivottable
        'etc
        '
        '
    End With

End Sub
Delete a specific Pivot Table
Sub DeletePivotTable()
    'PURPOSE: How to delete a specifc Pivot Table
    'SOURCE: www.TheSpreadsheetGuru.com

'Delete Pivot Table By Name
ActiveSheet.PivotTables("PivotTable1").TableRange2.Clear

End Sub

Delete all Pivot Tables in a Workbook
Sub DeleteAllPivotTables()

Dim sht As Worksheet
Dim pvt As PivotTable

    'Loop Through Each Pivot Table In Currently Viewed Workbook
    For Each sht In ActiveWorkbook.Worksheets
        For Each pvt In sht.PivotTables
            pvt.TableRange2.Clear
        Next pvt
    Next sht

End Sub

Rapport indeling - Compacte weergave, Overzichtsweergave, Tabelweergave
'Compacte weergave
ActiveSheet.PivotTables("PivotClCsNmbrs").RowAxisLayout xlCompactRow

'Overzichtsweergave
ActiveSheet.PivotTables("PivotClCsNmbrs").RowAxisLayout xlOutlineRow

'Tabelweergave
ActiveSheet.PivotTables("PivotClCsNmbrs").RowAxisLayout xlTabularRow
Repeat labels
'Inschakelen Labels herhalen
ActiveSheet.PivotTables("Pivot1").RepeatAllLabels xlRepeatLabels
piv1.RepeatAllLabels xlRepeatLabels

'Uitschakelen Labels herhalen
piv1.RepeatAllLabels xlDoNotRepeatLabels

Subtotals
pt.PivotFields("PivField1").Subtotals = Array(False, False, False, False, False, False, False, False, False, False, False, False)

 

Add Pivot Fields
Sub Adding_PivotFields()  'PURPOSE: Show how to add various Pivot Fields to Pivot Table
Dim pvt As PivotTable

Set pvt = ActiveSheet.PivotTables("PivotTable1")

'Add item to the Report Filter
pvt.PivotFields("Year").Orientation = xlPageField

'Add item to the Column Labels
pvt.PivotFields("Month").Orientation = xlColumnField

'Add item to the Row Labels
pvt.PivotFields("Account").Orientation = xlRowField

'Position Item in list
pvt.PivotFields("Year").Position = 1

'Format Pivot Field
pvt.PivotFields("Year").NumberFormat = "#,##0"

'Turn on Automatic updates/calculations --like screenupdating to speed up code
pvt.ManualUpdate = False

End Sub

Add Calculated Pivot Fields
Sub AddCalculatedField()   'PURPOSE: Add a calculated field to a pivot table
Dim pvt As PivotTable
Dim pf As PivotField

'Set Variable to Desired Pivot Table
Set pvt = ActiveSheet.PivotTables("PivotTable1")

'Set Variable Equal to Desired Calculated Pivot Field
For Each pf In pvt.PivotFields
If pf.SourceName = "Inflation" Then Exit For
Next

'Add Calculated Field to Pivot Table
pvt.AddDataField pf

End Sub

Add A Values Field
Sub AddValuesField()    'PURPOSE: Add A Values Field to a Pivot Table
Dim pvt As PivotTable
Dim pf As String
Dim pf_Name As String

pf = "Salaries"
pf_Name = "Sum of Salaries"

Set pvt = ActiveSheet.PivotTables("PivotTable1")

pvt.AddDataField pvt.PivotFields("Salaries"), pf_Name, xlSum

End Sub

Remove Pivot Fields
Sub RemovePivotField()    ‘PURPOSE: Remove a field from a Pivot Table
    ‘Removing Filter, Columns, Rows
ActiveSheet.PivotTables(“PivotTable1”).PivotFields(“Year”).Orientation = xlHidden

‘Removing Values
ActiveSheet.PivotTables(“PivotTable1”).PivotFields(“Sum of Salaries”).Orientation = xlHidden

End Sub

Remove Calculated Pivot Fields

Sub RemoveCalculatedField()

‘PURPOSE: Remove a calculated field from a pivot table
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pvt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem

‘Set Variable to Desired Pivot Table
Set pvt = ActiveSheet.PivotTables(“PivotTable1”)

‘Set Variable Equal to Desired Calculated Data Field
For Each pf In pvt.DataFields
If pf.SourceName = “Inflation” Then Exit For
Next

‘Hide/Remove the Calculated Field
pf.DataRange.Cells(1, 1).PivotItem.Visible = False

End Sub

Refresh Pivot Table(s)

Refresh Pivot Table(s)

Sub RefreshingPivotTables()
‘PURPOSE: Shows various ways to refresh Pivot Table Data
‘SOURCE: www.TheSpreadsheetGuru.com

‘Refresh A Single Pivot Table
ActiveSheet.PivotTables(“PivotTable1”).PivotCache.Refresh

‘Refresh All Pivot Tables
ActiveWorkbook.RefreshAll

End Sub

Report Filter On A Single Item

Report Filter On A Single Item

Sub ReportFiltering_Single()
‘PURPOSE: Filter on a single item with the Report Filter field
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pf As PivotField

Set pf = ActiveSheet.PivotTables(“PivotTable2”).PivotFields(“Fiscal_Year”)

‘Clear Out Any Previous Filtering
pf.ClearAllFilters

‘Filter on 2014 items
pf.CurrentPage = “2014”

End Sub

Report Filter On Multiple Items

Report Filter On Multiple Items

Sub ReportFiltering_Multiple()
‘PURPOSE: Filter on multiple items with the Report Filter field
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pf As PivotField

Set pf = ActiveSheet.PivotTables(“PivotTable2”).PivotFields(“Variance_Level_1”)

‘Clear Out Any Previous Filtering
pf.ClearAllFilters

‘Enable filtering on multiple items
pf.EnableMultiplePageItems = True

‘Must turn off items you do not want showing
pf.PivotItems(“Jan”).Visible = False
pf.PivotItems(“Feb”).Visible = False
pf.PivotItems(“Mar”).Visible = False

End Sub

Clear Report Filter

Clear Report Filter

Sub ClearReportFiltering()
‘PURPOSE: How to clear the Report Filter field
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pf As PivotField

Set pf = ActiveSheet.PivotTables(“PivotTable2”).PivotFields(“Fiscal_Year”)

‘Option 1: Clear Out Any Previous Filtering
pf.ClearAllFilters

‘Option 2: Show All (remove filtering)
pf.CurrentPage = “(All)”

End Sub

Change Pivot Table Data Source Range

Change Pivot Table Data Source Range

Sub ChangePivotDataSourceRange()
‘PURPOSE: Change the range a Pivot Table pulls from
‘SOURCE: www.TheSpreadsheetGuru.com

Dim sht As Worksheet
Dim SrcData As String
Dim pvtCache As PivotCache

‘Determine the data range you want to pivot
Set sht = ThisWorkbook.Worksheets(“Sheet1”)
SrcData = sht.Name & “!” & Range(“A1:R100”).Address(ReferenceStyle:=xlR1C1)

‘Create New Pivot Cache from Source Data
Set pvtCache = ActiveWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=SrcData)

‘Change which Pivot Cache the Pivot Table is referring to
ActiveSheet.PivotTables(“PivotTable1”).ChangePivotCache (pvtCache)

End Sub

Grand Totals

 Grand Totals

Sub PivotGrandTotals()
‘PURPOSE: Show setup for various Pivot Table Grand Total options
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pvt As PivotTable

Set pvt = ActiveSheet.PivotTables(“PivotTable1”)

‘Off for Rows and Columns
pvt.ColumnGrand = False
pvt.RowGrand = False

‘On for Rows and Columns
pvt.ColumnGrand = True
pvt.RowGrand = True

‘On for Rows only
pvt.ColumnGrand = False
pvt.RowGrand = True

‘On for Columns Only
pvt.ColumnGrand = True
pvt.RowGrand = False

End Sub

Report Layout

Report Layout

Sub PivotReportLayout()
‘PURPOSE: Show setup for various Pivot Table Report Layout options
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pvt As PivotTable

Set pvt = ActiveSheet.PivotTables(“PivotTable1”)

‘Show in Compact Form
pvt.RowAxisLayout xlCompactRow

‘Show in Outline Form
pvt.RowAxisLayout xlOutlineRow

‘Show in Tabular Form
pvt.RowAxisLayout xlTabularRow

End Sub

Formatting A Pivot Table's Data

Formatting A Pivot Table’s Data

Sub PivotTable_DataFormatting()
‘PURPOSE: Various ways to format a Pivot Table’s data
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pvt As PivotTable

Set pvt = ActiveSheet.PivotTables(“PivotTable1”)

‘Change Data’s Number Format
pvt.DataBodyRange.NumberFormat = “#,##0;(#,##0)”

‘Change Data’s Fill Color
pvt.DataBodyRange.Interior.Color = RGB(0, 0, 0)

‘Change Data’s Font Type
pvt.DataBodyRange.Font.FontStyle = “Arial”

End Sub

Formatting A Pivot Field's Data

Formatting A Pivot Field’s Data

Sub PivotField_DataFormatting()
‘PURPOSE: Various ways to format a Pivot Field’s data
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pf As PivotField

Set pf = ActiveSheet.PivotTables(“PivotTable1”).PivotFields(“Months”)

‘Change Data’s Number Format
pf.DataRange.NumberFormat = “#,##0;(#,##0)”

‘Change Data’s Fill Color
pf.DataRange.Interior.Color = RGB(219, 229, 241)

‘Change Data’s Font Type
pf.DataRange.Font.FontStyle = “Arial”

End Sub

Expand/Collapse Entire Field Detail

Expand/Collapse Entire Field Detail

Sub PivotField_ExpandCollapse()
‘PURPOSE: Shows how to Expand or Collapse the detail of a Pivot Field
‘SOURCE: www.TheSpreadsheetGuru.com

Dim pf As PivotField

Set pf = ActiveSheet.PivotTables(“PivotTable1”).PivotFields(“Month”)

‘Collapse Pivot Field
pf.ShowDetail = False

‘Expand Pivot Field
pf.ShowDetail = True

End Sub

Loop through pivot table
For cntr = 2 To ptProduct.RowRange.Rows.Count
cmbFilterService.AddItem ptProduct.RowRange.Cells(cntr, 1).Value
Next

 

 

String handling

t
Split a string
Dim SplitArray() as string '(Dim verplicht as string)
SplitArray() = Split(TeSplitsenString, "/")
For ArrCntr = LBound(SplitArray()) To UBound(SplitArray())
If Trim(SplitArray(ArrCntr)) = TestString Then
....
End If
Next

Tables

t
Add aTable
Application.CutCopyMode = False
wsReport.ListObjects.Add(xlSrcRange, Range("$A$6:$I$7"), , xlYes).Name = "FtrTable"
wsReport.ListObjects("FtrTable").TableStyle = "TableStyleMedium10" '"TableStyleMedium17" '"TableStyleLight10"
wsReport.Range("$A$6:$I$7").VerticalAlignment = xlTop
Add a Column to a Table
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("Sales_Table")
'add a new column as the 5th column in the table
tbl.ListColumns.Add(5).Name = "TAX"
'add a new column at the end of the table
tbl.ListColumns.Add.Name = "STATUS"
Add a Row to a Table
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("Sales_Table")
‘add a row at the end of the table
tbl.ListRows.Add
‘add a row as the fifth row of the table (counts the headers as a row)
tbl.ListRows.Add 5
Delete Row or Column
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("Sales_Table")
tbl.ListColumns(2).Delete
tbl.ListRows(2).Delete
Add Row and Enter Data
Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("Sales_Table")
Dim newrow As ListRow
Set newrow = tbl.ListRows.Add
With newrow
    .Range(1) = 83473
    .Range(2) = "HJU -64448"
    .Range(3) = 5
End With
Add/Overwrite Data in a Specific Record
Dim ws AsWorksheet
Set ws =ActiveSheet
Dim tbl AsListObject
Set tbl =ws.ListObjects("Sales_Table")
Withtbl.ListRows(3)
   .Range(3)= 8
   .Range(6)= "CASH"
End With
Check if activecell is in table
If Intersect(ActiveCell, ActiveSheet.ListObjects("Table1").DataBodyRange) Is Nothing Then
 MsgBox "activecell not in Table1"
Else
 MsgBox "activecell in Table1"
End If...
Sort a table

Sort on values

Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("Sales_Table")
Dim sortcolumn As Range
Set sortcolumn = Range("Sales_Table[TRANS_VALUE]")
With tbl.Sort
   .SortFields.Clear
   .SortFields.Add Key:=sortcolumn, SortOn:=xlSortOnValues, Order:=xlDescending
   .Header = xlYes
   .Apply
End With

 

Sort on colors
To sort by cell colour, specify this in the SortOn parameter of the Add method. You then have to specify the colour to sort by using the SortOnValue property of the SortField object (see below).

Dim ws As Worksheet
Set ws = ActiveSheet
Dim tbl As ListObject
Set tbl = ws.ListObjects("Sales_Table")
Dim sortcolumn As Range
Set sortcolumn = Range("Sales_Table[TRANS_VALUE]")
With tbl.Sort
  .SortFields.Clear
  .SortFields.Add(Key:=sortcolumn, Order:=xlAscending, SortOn:=xlSortOnCellColor).SortOnValue.Color =RGB(255, 255, 0)
  .Header = xlYes
  .Apply
End With
Select (parts of) a table
With these codes you can select different parts of a table.    
Entire Table: ActiveSheet.ListObjects("Table1").Range.Select    

Table Header Row: ActiveSheet.ListObjects("Table1").HeaderRowRange.Select    

Table Data: ActiveSheet.ListObjects("Table1").DataBodyRange.Select    

Third Column: ActiveSheet.ListObjects("Table1").ListColumns(3).Range.Select

Multiple Columns:
Dim ws As Worksheet
Dim tbl As ListObject

Set ws = Sheets("Sheet1")
Set tbl = ws.ListObjects(1)

Range(tbl &"[[Column1]:[Column5]]".Select

Third Column (Data Only):
ActiveSheet.ListObjects("Table1").ListColumns(3).DataBodyRange.Select

Select Row 4 of Table Data:
ActiveSheet.ListObjects("Table1").ListRows(4).Range.Select

Select 3rd Heading:
ActiveSheet.ListObjects("Table1").HeaderRowRange(3).Select

Select Data point in Row 3, Column 2:
ActiveSheet.ListObjects("Table1").DataBodyRange(3, 2).Select

Subtotals:
ActiveSheet.ListObjects("Table1").TotalsRowRange.Select

Disable autofill formula's in table

Application.AutoCorrect.AutoFillFormulasInLists = False
Enable/Disable autoextend table
For all tables:

Sub EnableTableAutoExpansion()
  Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
ws.ListObjects.AutoExpand = True
Next ws
End Sub

 

For a specific table:

Sub EnableSpecificTableAutoExpansion(tableName As String)
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
Dim tbl As ListObject
Set tbl = ws.ListObjects(tableName)
If Not tbl Is Nothing Then
tbl.AutoExpand = True
End If
Next ws
End Sub

Call with:

EnableSpecificTableAutoExpansion "Tab1"
Get column number from table header
[MyTable].Cells(2, [MyTable[MyColumn]].Column)
Table to Array
Sub MultiColumnTable_To_Array()

Dim myTable As ListObject
Dim myArray As Variant
Dim x As Long

'Set path for Table variable
  Set myTable = ActiveSheet.ListObjects("Table1")

'Create Array List from Table
  myArray = myTable.DataBodyRange

'Loop through each item in Third Column of Table (displayed in Immediate Window [ctrl + g])
  For x = LBound(myArray) To UBound(myArray)
    Debug.Print myArray(x, 3)
  Next x

End Sub

Titelbalk van een vba formulier verwijderen

Titelbalk van VBA formulier verwijderen

GEPUBLICEERD: 24 DECEMBER 2020 LAATST BIJGEWERKT: 29 JANUARI 2021
Soms is het wenselijk om de gehele titelbalk van een formulier te verwijderen. Bijvoorbeeld bij het tonen van een zogenaamd ‘splash screen’ bij het opstarten van een applicatie of bij het tonen van een formulier met een voortgangsbalk. In deze gevallen kan het fraaier zijn om een formulier te gebruiken zonder titelbalk.

Titelbalk van formulier verwijderen

De VBA formulieren hebben standaard geen optie om de titelbalk te verwijderen, maar met behulp van de Windows API is kan dit wel gerealiseerd worden. De code hiervoor moet in een aparte module gezet worden en kan dan eenvoudig aangeroepen worden in een formulier waar de titelbalk verwijderd moet worden. De code die in de module gezet moet worden is als volgt:

Private Const GWL_STYLE = -16
Private Const WS_CAPTION = &HC00000

#If VBA7 Then
    Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
    #If Win64 Then
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #Else
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long) As LongPtr
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
    #End If
    Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hWnd As LongPtr) As Long
#Else
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function DrawMenuBar Lib "user32" (ByVal hWnd As Long) As Long
#End If

Public Sub HideFormTitleBar(frm As Object)
    #If VBA7 Then
        Dim lStyle As LongPtr, lFrmHandle As LongPtr
    #Else
        Dim lStyle As Long, lFrmHandle As Long
    #End If
    lFrmHandle = FindWindow("ThunderDFrame", frm.Caption)
    lStyle = GetWindowLong(lFrmHandle, GWL_STYLE)
    lStyle = lStyle And Not WS_CAPTION
    SetWindowLong lFrmHandle, GWL_STYLE, lStyle
    DrawMenuBar lFrmHandle
End Sub

Deze code werkt zowel in de 32 als in de 64 bits versie. De titelbalk van een formulier kan dan verwijderd worden door de volgende regel aan de UserForm_Initialize gebeurtenis toe te voegen:

Private Sub  UserForm_Initialize()
    HideFormTitleBar Me
End Sub

Dit kan als gezegd gebruikt worden voor een splash screen. Maak daarvoor een nieuw formulier aan en zet daarop de zaken die getoond moeten worden op het splash screen, zoals logo en naam van de applicatie. Noem dit formulier frmSplash. In Excel kan dit splash screen getoond worden door de volgende code in de Workbook_Open gebeurtenis van ThisWorkbook klassenmodule:

Private Sub Workbook_Open()
    ActiveWindow.Visible = False
    frmSplash.Show
    Windows(ThisWorkbook.Name).Visible  = True
End Sub

Als dit splash screen 5 seconden zichtbaar moet zijn, zet dan de volgende code in de UserForm_Activate gebeurtenis van het formulier:

Private Sub UserForm_Activate()
    Application.Wait (Now + TimeValue("00:00:05"))
    Unload Me
End Sub

Op deze manier wordt bij het opstarten van het Excel-bestand eerst 5 seconden het splash screen getoond, waarna het Excel bestand zichtbaar wordt.

Share This