The sample demonstrates How to Use VBA in an excel workbook.
private void btnRun_Click(object sender, System.EventArgs e) { Workbook workbook = new Workbook(); //Initialize worksheet workbook.LoadFromFile(@"..\..\..\..\..\Data\VBASample.xls"); Worksheet sheet = workbook.Worksheets[0]; //Writes new sheet name sheet.Range["A1"].Text = this.textBox1.Text; workbook.SaveToFile("Sample.xls"); ExcelDocViewer(workbook.FileName); } private void ExcelDocViewer( string fileName ) { try { System.Diagnostics.Process.Start(fileName); } catch{} }
Private Sub btnRun_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRun.Click Dim workbook As Workbook = New Workbook() 'Initialize worksheet workbook.LoadFromFile("..\..\..\..\..\Data\VBASample.xls") Dim sheet As Worksheet = workbook.Worksheets(0) 'Writes new sheet name sheet.Range("A1").Text = Me.textBox1.Text workbook.SaveToFile("Sample.xls") ExcelDocViewer(workbook.FileName) End Sub Private Sub ExcelDocViewer(ByVal fileName As String) Try System.Diagnostics.Process.Start(fileName) Catch End Try End Sub