宏在 2016 Excel 中不起作用

宏在 2016 Excel 中不起作用
Private Sub ListBox1_Click()

        Application.ScreenUpdating = False
        Dim Filepath As String
        Filepath = Worksheets("Postavke").Range("B1").Value & "\" & ListBox1.Value

        Call load(Filepath)
        Worksheets("Radni Ekran").Activate

        If ListBox1.Value Like "*DELTA*" Then
            With ActiveSheet.ChartObjects("Chart 3").Chart
                ' Value (Y) Axis
                With .Axes(xlValue)
                .MaximumScale = 0.3
                .MinimumScale = -0.3
                End With
            End With
            Sheets("Radni Ekran").Range("C41").Value = 0
            Sheets("Radni Ekran").Range("D41").Value = 0
        Else
            With ActiveSheet.ChartObjects("Chart 3").Chart
                ' Value (Y) Axis
                With .Axes(xlValue)
                .MaximumScale = 1
                .MinimumScale = 0
                End With
            End With
            Sheets("Radni Ekran").Range("C41").Value = Sheets("Priprema").Range("H2").Value
            Sheets("Radni Ekran").Range("D41").Value = Sheets("Priprema").Range("I2").Value
        End If

        Call TransposeData

        Application.ScreenUpdating = True

End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
    Dim fileList() As String
    Dim fName As String
    Dim fPath As String
    Dim I As Integer


         'define the directory to be searched for files
    fPath = Worksheets("Postavke").Range("B1").Value
    If Dir(fPath, vbDirectory) = "" Then
    MsgBox "Problem!! Nedostupna lokacija" & vbNewLine & fPath
    End If

  If Target.Column = 2 And Target.Row = 3 Then
        ListBox1.Clear
        ListBox1.ListIndex = -1
      fName = Dir(fPath & "\*" & Range("B3").Value & "*.txt")
    While fName <> ""
         'add fName to the list
        I = I + 1
        ReDim Preserve fileList(1 To I)
        fileList(I) = fName
         'get next filename
        fName = Dir()
    Wend
     'see if any files were found
    If I = 0 Then
        MsgBox "Nije pronađena ni jedna datoteka u" & vbNewLine & fPath & "\*" & Range("D3").Value & "*.txt"
        Exit Sub
    End If
     'cycle through the list and add to listbox
    For I = 1 To UBound(fileList)
        ListBox1.AddItem fileList(I)
    Next
        Range("B3").Select
  End If

End Sub

在线I = I + 1我收到错误

答案1

错误是因为你没有给某样东西指定一个“我”,

你使用的 I 没有任何值,所以程序很困惑,它无法决定如何将 1 加到零然后将其存储到“I”

只需在“Dim I as Integer”后添加“I = 0”,这将解决问题

相关内容