Toon posts:

[vba] public vars verliezen waarde

Pagina: 1
Acties:
  • 201 views sinds 30-01-2008
  • Reageer

Verwijderd

Topicstarter
Aangepast:
Deze code veroorzaakt een fout die niet wordt weergegeven door excel. Probleem is dat dan alle publicvars worden leeggegooid. De oorzaak daarvan had ik reeds gevonden, maar 't probleem blijft bestaan. Als ik door de code step dan krijg ik bij de regel: Sheets(Tabnaam).Delete de meldig 'Kan de onderbrekingsmodus momenteel niet activeren'. Waarschijnlijk leidt dit tot mijn probleem... Iemand een suggestie?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Sub VerwijderBlad()

On Error GoTo UserEnd

Dim ActiveStukLijst
Dim Rij
Dim PosNr
Dim TbType 'tabbladtype
Dim Tabnaam As String 'de naam van de nieuw aan te maken tab

ActiveStukLijst = ActiveSheet.Name

Rij = ActiveCell.Row
PosNr = Range("C" & Rij).Value
TbType = Range("G" & Rij).Value
Tabnaam = TbType & "_" & ActiveStukLijst & "_" & PosNr

'controle op alle verplichte gegevens
  
    ToggleSU ("false")
      
    ActiveSheet.Unprotect
    ActiveSheet.Range("C" & Rij & ":K" & Rij).Value = ""
      ActiveSheet.Protect

    If SheetExists(Tabnaam) = True Then
     Sheets(Tabnaam).Delete
    End If
    
    ToggleSU ("true")
    Exit Sub

Exit Sub
UserEnd: Call UserError(Error, Err)

End Sub

  • Pooh
  • Registratie: April 2001
  • Niet online

Pooh

Lees eens een boek

Kun je je probleem reproduceren in zo min mogelijk regels code? :?

Dit is me echt een beetje te veel...

Verwijderd

Topicstarter
Oorzaak gevonden, oplossing nog niet, maar goed; dat lukt wel. Wellicht handig voor als iemand ooit nog hetzelfde tegen mocht komen:

MS KB: Q155457
-->
In earlier versions of Microsoft Excel and Visual Basic for Applications, there is a mode in the internal code that stops the code execution but keeps the stack variables. This is by design of Visual Basic for Applications.

In Microsoft Excel 97 and Excel 98, this mode was removed from the internal code to make it consistent with all other Visual Basic for Applications programs. When Visual Basic for Applications encounters an error that halts a macro, it resets the project stack, including all public variables.

Verwijderd

Topicstarter
Toch nog maar weer een keer, want kom er niet uit. Heb nu bijna al het onnodige eruit gegooid, en op verzoek de code die het probleem veroorzaakt drastisch ingekort.