Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports Excel = Microsoft.Office.Interop.Excel
- Imports Microsoft.Office
- Public Class Form9
- Dim appXL As Excel.Application = Nothing
- Dim wbXL As Excel.Workbook = Nothing
- Dim shXL As Excel.Worksheet = Nothing
- Dim raXL As Excel.Range = Nothing
- Dim sheetBaru As Excel.Worksheet
- Dim nomerSheet As Integer = 4
- Dim namaSheetBaru As String = "Kertas Baru2"
- Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
- appXL = New Excel.Application
- wbXL = appXL.Workbooks.Open("D:\fileExcel\Latihan100.xlsx")
- appXL.Visible = True
- With wbXL
- 'Menambahkan sheet baru ke workbook
- .Worksheets.Add(After:=.Worksheets(nomerSheet))
- End With
- shXL = wbXL.Worksheets(5)
- shXL.Name = namaSheetBaru
- For i = 1 To 6
- For j = 1 To 2
- shXL.Cells(i, j) = 200
- Next j
- Next i
- 'Simpan perubahan di file excel
- wbXL.Save()
- appXL.UserControl = True
- raXL = Nothing
- wbXL = Nothing
- shXL = Nothing
- appXL = Nothing
- Exit Sub
- Err_Handler:
- MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement