BackgroundWorker无法正常工作

时间:2015-09-14 17:05:36

标签: .net vba backgroundworker

您好我需要使用vb net帮助我的程序上的后台工作人员,每次我添加后台工作程序,程序没有使用按钮4做出响应,我做错了什么?

请在下面找到我使用的代码:

Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
    BackgroundWorker1.RunWorkerAsync()
End Sub

Private Sub BackgroundWorker1_DoWork(sender As Object, e As ComponentModel.DoWorkEventArgs) Handles BackgroundWorker2.DoWork

    For I = 0 To 200 'Telling the program to count from 0 - 200
        runMacro()

        BackgroundWorker1.ReportProgress(I)
        System.Threading.Thread.Sleep(1000)
    Next

End Sub

Private Sub BackgroundWorker1_ProgressChanged(sender As Object, e As ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
    ProgressBar1.Value = e.ProgressPercentage
End Sub

找到我的runMacro()的下面代码:

Private Sub runMacro()
    '~~> Define your Excel Objects
    Dim xlApp As New Excel.Application
    Dim xlWorkBook As Excel.Workbook

    '~~> Start Excel and open the workbook.
    xlWorkBook = xlApp.Workbooks.Open("\Projects\MV_tool\MV_tool\audit\macroaudit.xlsm")
    ' xlApp.Visible = False
    '~~> Run the macros.
    xlApp.Run("Module1.Txt_Excel_tool")
    'Source1.Close(SaveChanges:=False)
    'For i = 0 To 100
    'BackgroundWorker2.ReportProgress(i)
    ' Next
    'xlApp.Run("Module2.Txt_Excel_tool")
    '~~> Clean-up: Close the workbook and quit Excel.
    xlApp.Visible = True
    xlWorkBook.Close(False)
    'Source1.Close(SaveChanges:=False)
    '~~> Quit the Excel Application
    ' xlApp.Quit()


End Sub

0 个答案:

没有答案