5

リストボックスは、選択した値を「n」に割り当てていません。リストボックスから値を選択するかどうかに関係なく、「n」の値は0です。私は学んでいるので、私が見逃しているのは単純なことかもしれません...提案?ありがとう!

Private Sub UserForm_Initialize()

With cbomonth
    .AddItem "January"
    .AddItem "February"
End With
With cboyear
    .AddItem "2013"
    .AddItem "2014"
End With
With cboteam
    .AddItem "Team1"
    .AddItem "Team2"
End With
With cbodocument
    .AddItem "Task1"
    .AddItem "Task2"
End With
With ListBox1
.AddItem "Name"
.AddItem "Name"
End With
cboteam.ListIndex = 0
cboyear.ListIndex = 4
cbomonth.ListIndex = 6
cbodocument.ListIndex = 1

End Sub

Private Sub cmdSubmit_Click()

    Dim year As String
    Dim month As String
    Dim days As Integer
    Dim team As String
    Dim n as Long
    Dim tallboxynames As Variant
    Dim tallynewfile As String

    Unload Me

    year = cboyear.Value
    month = cbomonth.Value
    team = cboteam.Value
    document = cbodocument.Value

    TallyPath = "\\network path\Tally of orders\Master Template\"
    TallyPath1 = "\\network path\Tally of orders\" & year & "\"
    TallyPath2 = "\\network path\Tally of orders\" & year & "\" & month & "\"
    TallyTemplate = "Tally_Template_ver1.xls"

If document = "Tally Sheets" Then
    For n = 0 To ListBox1.ListCount - 1
        If ListBox1.Selected(n) Then
            tallynewfile = ListBox1.Selected(n) & ".xls"
        Else
            MsgBox "No data from listbox"
        End If
If Len(Dir(TallyPath1, vbDirectory)) = 0 Then
    MkDir TallyPath1
End If
If Len(Dir(TallyPath2, vbDirectory)) = 0 Then
    MkDir TallyPath2
    FileCopy TallyPath & TallyTemplate, TallyPath2 & tallynewfile
End If
    Next n
End If
Exit Sub
End Sub
4

2 に答える 2

11

Unload Meを手順の最後に移動します:

Private Sub cmdSubmit_Click()
    ' code here ...
    Unload Me
End Sub

選択したアイテムを取得するには、ListBox1.MultiSelect = 0(fmMultiSelectSingle)の場合に値を使用します。

Me.ListBox1.Value

MultiSelect> 0の場合は、Selectedプロパティを使用します(例:

Private Function GetSelectedItems() As String
    Dim text As String
    Dim i As Integer
    For i = 0 To Me.ListBox1.ListCount - 1
        If Me.ListBox1.Selected(i) Then
            text = text & Me.ListBox1.List(i) & vbNewLine
        End If
    Next i
    MsgBox "Selected items are: " & text
    GetSelectedItemsText = text
End Function
于 2013-03-18T20:16:48.267 に答える
1

それ以外の

Unload Me

使用してみてください

Me.Hide

フォーム上unloadのすべての値が削除されると。を使用すると保持されますHide

于 2013-03-18T18:15:39.790 に答える