View Single Post
Old 12-31-2014, 04:18 AM
george_m george_m is offline
Join Date: Mar 2012
Posts: 20
Default Adding worksheets

I've problems with adding worksheets in excel through VB code.

I've created excel file with VBA code - BeforeSave event where few new worksheets are created (MAKRO.xlsm). The event is triggered only if Cell(1,1) value is 0 and excel file alone works fine.

I've also prepared program in VB, where this file is opened and managed - code below. Problem is that new worksheets are not created when triggering BerforeSave event in excel file.

   Dim APP As New Excel.Application
    Dim BOOK As Excel.Workbook
    Dim SHEET As Excel.Worksheet

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

        BOOK = APP.Workbooks.Open(Application.StartupPath & "\MAKRO.xlsm")

    End Sub

    Private Sub Form1_FormClosed(sender As Object, e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed

        SHEET = APP.Sheets.Item(2)

        SHEET.Cells(1, 1).value = 0

    End Sub
Reply With Quote