SHARE
TWEET

Input Data ke Worksheet yg Baru di Buat

stevennathaniel Jan 28th, 2016 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Imports Excel = Microsoft.Office.Interop.Excel
  2.  
  3. Imports Microsoft.Office
  4.  
  5. Public Class Form9
  6.  
  7.     Dim appXL As Excel.Application = Nothing
  8.  
  9.     Dim wbXL As Excel.Workbook = Nothing
  10.  
  11.     Dim shXL As Excel.Worksheet = Nothing
  12.  
  13.     Dim raXL As Excel.Range = Nothing
  14.  
  15.     Dim sheetBaru As Excel.Worksheet
  16.  
  17.     Dim nomerSheet As Integer = 4
  18.  
  19.     Dim namaSheetBaru As String = "Kertas Baru2"
  20.  
  21.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  22.  
  23.         appXL = New Excel.Application
  24.  
  25.         wbXL = appXL.Workbooks.Open("D:\fileExcel\Latihan100.xlsx")
  26.  
  27.         appXL.Visible = True
  28.  
  29.         With wbXL
  30.  
  31.  
  32.  
  33.  
  34.             'Menambahkan sheet baru ke workbook
  35.             .Worksheets.Add(After:=.Worksheets(nomerSheet))
  36.  
  37.         End With
  38.  
  39.         shXL = wbXL.Worksheets(5)
  40.  
  41.         shXL.Name = namaSheetBaru
  42.  
  43.         For i = 1 To 6
  44.  
  45.             For j = 1 To 2
  46.  
  47.                 shXL.Cells(i, j) = 200
  48.  
  49.             Next j
  50.         Next i
  51.  
  52.         'Simpan perubahan di file excel
  53.         wbXL.Save()
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.         appXL.UserControl = True
  61.  
  62.         raXL = Nothing
  63.  
  64.         wbXL = Nothing
  65.  
  66.         shXL = Nothing
  67.  
  68.         appXL = Nothing
  69.  
  70.         Exit Sub
  71.  
  72. Err_Handler:
  73.  
  74.         MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
  75.  
  76.  
  77.  
  78.     End Sub
  79. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top