Hello I've found a working script for what I want to do:
https://www.daniweb.com/programming/software-development/threads/384778/copy-files-from-a-list-in-excel

Imports Excel = Microsoft.Office.Interop.Excel

Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        'get the last saved settings

        btnCopy.Enabled = False

        txtExcel.Text = My.Settings.ExcelFile
        txtSrce.Text = My.Settings.SourceFolder
        txtDest.Text = My.Settings.DestinationFolder

        SetCopyButtonText()

    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click

        'save the user entered values for the next session

        My.Settings.ExcelFile = txtExcel.Text
        My.Settings.SourceFolder = txtSrce.Text
        My.Settings.DestinationFolder = txtDest.Text

    End Sub

    Private Sub btnExcel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExcel.Click

        'browse for an Excel file containing the list of files to copy

        OpenFileDialog1.Title = "Select an Excel File"

        If txtExcel.Text <> "" Then
            OpenFileDialog1.InitialDirectory = My.Computer.FileSystem.GetParentPath(txtExcel.Text)
        End If

        OpenFileDialog1.Filter = "Excel Files|*.xls"

        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
            txtExcel.Text = OpenFileDialog1.FileName
            SetCopyButtonText()
        End If

    End Sub

    Private Sub btnGetSrce_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetSrce.Click

        'browse for a folder containing the files to copy

        FolderBrowserDialog1.SelectedPath = txtSrce.Text

        If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
            txtSrce.Text = FolderBrowserDialog1.SelectedPath
            SetCopyButtonText()
        End If

    End Sub

    Private Sub btnGetDest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetDest.Click

        'browse for a folder that will contain the copied files

        FolderBrowserDialog2.SelectedPath = txtDest.Text

        If FolderBrowserDialog2.ShowDialog() = DialogResult.OK Then
            txtDest.Text = FolderBrowserDialog2.SelectedPath
            SetCopyButtonText()
        End If

    End Sub

    Private Sub SetCopyButtonText()

        'set copy button text and status - note - the button will remain disabled
        'until all required parameters have been supplied.

        btnCopy.Text = "Copy files" & vbCrLf _
                     & "    From: " & txtSrce.Text & vbCrLf _
                     & "      To: " & txtDest.Text

        btnCopy.Enabled = txtSrce.Text <> "" And txtDest.Text <> "" And txtExcel.Text <> ""

    End Sub

    Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click

        'copy the files specified in column 1 of the first sheet of the Excel workbook
        'from the folder given by txtSrce to the folder given by txtDest

        Dim xls As New Excel.Application
        Dim sheet As Excel.Worksheet

        xls.Workbooks.Open(txtExcel.Text)
        sheet = xls.ActiveWorkbook.Sheets(1)

        Dim row As Integer = 1

        Do Until sheet.Cells(row, 1) Is Nothing OrElse Len(Trim(sheet.Cells(row, 1).value)) = 0

            Dim srce = My.Computer.FileSystem.CombinePath(txtSrce.Text, sheet.Cells(row, 1).value)
            Dim dest = My.Computer.FileSystem.CombinePath(txtDest.Text, sheet.Cells(row, 1).value)

            My.Computer.FileSystem.CopyFile(srce, dest)
            txtLog.AppendText("copy" & vbTab & srce & vbCrLf)
            txtLog.AppendText("  to" & vbTab & dest & vbCrLf)

            row += 1

        Loop

        xls.Quit()

    End Sub

End Class

It's for copying file who are listed in a Excel sheet. Now I wan't to add an progress bar to this form thats's included with the script. I've no idea how to fix this. I hope someone wan't to help me.

Recommended Answers

All 3 Replies

Create a ProgressBar named prgFileCopy and set

prgFileCopy.Minimum = 0

Calculate the number of files to be copied and assign that as

prgFileCopy.Maximum = numFiles

Start by setting

prgFileCopy.Value = 0

and after each file copy has completed (in the loop) do

prgFileCopy.Value += 1

You might want to dock the prgFilecopy to the bottom of the form.

Thank you!
But how can I count all files (rows) in the excel file? Because the number different every time.
Thank you in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.