Ich bin neu in VBA, also könnte ich etwas verpasst haben.VBA: Verwenden eines Wörterbuchs außerhalb eines Benutzerformulars
Ich fülle ein Wörterbuch DicOption
in einem Sub aus einem Modul. Dies ist die sub:
Public Sub ExchangeToDicOption()
Static DicOption As Object
Dim LR As Long
Dim Rg As Range
Dim ws As Worksheet
Dim i As Long
Set ws = ActiveWorkbook.Worksheets(2)
Set Rg = ws.Columns(2)
If Not DicOption Is Nothing Then
DicOption.RemoveAll
End If
LR = Rg.Find(What:="*", Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, MatchCase:=False).Row
Set DicOption = CreateObject("Scripting.Dictionary")
If LR > 1 Then
For i = 2 To LR
DicOption.Add key:=Cells(i, 1).Value, Item:=Cells(i, 2).Value
Next i
End If
End Sub
Aber das Wörterbuch scheint sich zu leeren, wenn es seine process.I endet am die Unter ExchangeToDicOption
in UserForm_Initialize aufrufen. Creation_step ist ein Schlüssel in DicOption
.
Private Sub UserForm_Initialize()
Dim control As control
Dim opt As String
Call ExchangeToDicOption
opt = DicOption(Creation_step)
With UBidStatus
Select Case opt
Case Is > 0
For Each control In UBidStatus.Controls
control.Enabled = False
Next control
With UBidStatus
.Image4.Enabled = True
.LProject.Enabled = True
.LClient.Enabled = True
.Label6.Enabled = True
.Label7.Enabled = True
.IProjectinfoNOK.Enabled = True
.IProjectinfoOK.Enabled = True
.LProjectinfo.Enabled = True
.CBProjectinfo.Enabled = True
.IProjectinfoNOK.Visible = True
.IProjectinfoOK.Visible = False
End With
ect....
Ich habe auch versucht Public DicOption as Object
als globalen Variable zu verwenden (vor allem meiner subs in Fenster-Modul bearbeiten), aber es hat nicht funktioniert. Vielen Dank für Ihre Hilfe !!
Ich hatte zuvor auf diesen Thread verweisen, um mir zu helfen, meinen Code http://stackoverflow.com/questions/22382729/setting-a-global-scripting-dictionary-invisual-basic-for-applications-vba – Gab
zu vervollständigen Sie sollten wahrscheinlich die Goto Fill, Else und Fill-Label entfernen ... und verschieben Sie das Ende If bis zu wo Sie die Else haben. Es ist schlechte Form, einen Teil von If Goto den anderen Teil zu haben. Macht logisch keinen Sinn. Das wird dein Problem nicht lösen, es ist einfach keine gute Programmierung. – Rdster
Danke für deinen Kommentar @Rdster, ich dachte auch, dass es komisch ist, aber ich denke, dass ich mich mehr auf das Wörterbuchproblem konzentrierte. Ich werde Ihren Rat annehmen und diesen Code ändern. – Gab