I have edited your code like I think ...
Please try if it is working.
Greetings
Ralf
Private Sub PictureBox2_Click(sender As Object, e As EventArgs) Handles PictureBox2.Click
Try
SaveFileDialog1.Filter = "Excel File|*.xlsx"
SaveFileDialog1.Title = "Save an Excel File"
Application.EnableVisualStyles()
If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
If SaveFileDialog1.FileName <> "" Then
PictureBox2.Visible = True
ListView_Columns = ListView1.Columns
ListView_Items = ListView1.Items
BackgroundWorker1.RunWorkerAsync()
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private ListView_Columns As System.Windows.Forms.ListView.ColumnHeaderCollection
Private ListView_Items As System.Windows.Forms.ListView.ListViewItemCollection
Private Sub BackgroundWorker1_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
saveExcelFile(SaveFileDialog1.FileName)
End Sub
Private Sub BackgroundWorker1_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
PictureBox2.Visible = False
MessageBox.Show("DONE !!")
End Sub
Public Sub saveExcelFile(ByVal FileName As String)
Dim xls As New Excel.Application
Dim sheet As Excel.Worksheet
Dim i As Integer
xls.Workbooks.Add()
sheet = xls.ActiveWorkbook.ActiveSheet
Dim row As Integer = 1
Dim col As Integer = 1
For i = 0 To ListView_Columns.Count - 1
sheet.Cells(1, i + 1) = ListView_Columns(i).Text
Next
For i = 0 To ListView_Items.Count - 1
For j = 0 To ListView_Items(i).SubItems.Count - 1
sheet.Cells(i + 2, j + 1) = ListView_Items(i).SubItems(j).Text
Next
Next
row += 1
col = 1
sheet.Rows(1).Font.Name = "Microsoft Sans Serif"
sheet.Rows(1).Font.size = 16
sheet.Rows(1).Font.Bold = True
sheet.Rows(1).HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter
Dim mycol As System.Drawing.Color = System.Drawing.ColorTranslator.FromHtml("#20b2aa")
sheet.Rows(1).Font.color = mycol
sheet.Range("a2", "z1000").Font.Name = "Arial"
sheet.Range("a2", "z1000").Font.Size = 14
sheet.Range("a2", "z1000").HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter
sheet.Range("A1:X1").EntireColumn.AutoFit()
sheet.Range("A1:X1").EntireRow.AutoFit()
xls.ActiveWorkbook.SaveAs(FileName)
xls.Workbooks.Close()
xls.Quit()
End Sub