본문 바로가기
취미/Soft

[엑셀,VB] 엑셀 초단위로 세이브 해나가는 잘잘한 프로그램

by MDabsurd 2015. 8. 23.

 

 

 

Public Class Form1

    Dim excelObj As Object
    Dim excelbook As Object
    'Dim excelsheet As Object

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnConnect.Click

        Dim fileName As String = tBoxInputFileName.Text

        If Not My.Computer.FileSystem.FileExists(fileName) Then
            MsgBox(fileName & " does not exist")
            Exit Sub
        End If

        ' Set the object variable to refer to the file you want to use. 


        excelObj = GetObject(fileName).Application

        excelObj.Application.Visible = True

        Dim winCount As Integer = excelObj.Parent.Windows.Count()
        excelObj.Parent.Windows(winCount).Visible = True

        excelbook = excelObj.Workbooks(1)
        'excelsheet = excelbook.Sheets("Mydata") 'Region save 기능 구현시 Sheet Name 을 참조하게 한다

    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        Timer1.Interval = Convert.ToInt32(tBoxInterval.Text) * 1000
        Timer1.Start()
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If rbtnWholeSave.Checked = True Then
            excelbook.SaveAs(tBoxOutFileName.Text + Format(Now, "hh_mm_ss") + ".xlsx")
        Else
            MsgBox("Not Implemented Yet") ' Region 잡아 특정 형식으로 Save 하는 코드 추가
        End If


    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnStop.Click
        Timer1.Stop()
    End Sub

    Private Sub Form1_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
        excelObj = Nothing
        excelbook = Nothing
        'excelsheet = Nothing
    End Sub
End Class

댓글