VB hidden button on form
05:16 18 Jul 2013

I am using VB to search some data from a text file and then populate in excel. It's working. The problem is xl.visible=true makes the excel sheet to be visible at once & then the values keep on populating. I want to hide the excel till data population is complete. then make a button appear on the form which when clicked, will display the excel file.

Please help. Here is the code I'm using:

 Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    ' create an excel instance
    Dim xl = Microsoft.VisualBasic.CreateObject("Excel.Application")
    xl.Visible = False
    Dim wb = xl.Workbooks.Add()
    Dim sheet = wb.ActiveSheet

    ' find lines starting with any whitepace followed by MTV or MTB and capture
    ' the text after =
    Dim pattern = "(?<=\s*(MTV).*=).*"

    Dim i = 1
    Dim arg = {Microsoft.VisualBasic.ControlChars.CrLf, Microsoft.VisualBasic.ControlChars.Lf}


    If RichTextBox3.Text = "" Then
        MsgBox("No input. What will I process??")

        Else
        Timer1.Start()
            For Each line In File.ReadLines(RichTextBox3.Text)
                Dim match = Regex.Match(line, pattern)
                ' check each line and fill sheet

            If match.Success Then
                sheet.Cells(i, 1).Value = match.Value
                i += 1
            End If
        Next
    End If

    xl.Visible = True


End Sub
vb.net winforms