Advertisement
stevennathaniel

Input Data ke MS Excel yg Berhasil

Jan 26th, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.01 KB | None | 0 0
  1. Imports Excel = Microsoft.Office.Interop.Excel
  2.  
  3. Imports Microsoft.Office
  4.  
  5.  
  6. Public Class Form3
  7.  
  8.     Dim appXL As Excel.Application = Nothing
  9.  
  10.     Dim wbXL As Excel.Workbook = Nothing
  11.  
  12.     Dim shXL As Excel.Worksheet = Nothing
  13.  
  14.     Dim raXL As Excel.Range = Nothing
  15.  
  16.  
  17.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  18.  
  19.         'Source code input data ke MS Excel yg berhasil
  20.  
  21.         appXL = New Excel.Application
  22.  
  23.         wbXL = appXL.Workbooks.Open("D:\fileExcel\Latihan100.xlsx")
  24.  
  25.         shXL = wbXL.Worksheets("Sheet2")
  26.  
  27.         shXL.Activate()
  28.  
  29.  
  30.         appXL.Visible = True
  31.  
  32.         shXL.Cells(1, 1) = TextBox1.Text
  33.  
  34.         shXL.Cells(1, 2) = TextBox2.Text
  35.  
  36.  
  37.  
  38.         appXL.UserControl = True
  39.  
  40.         raXL = Nothing
  41.  
  42.         wbXL = Nothing
  43.  
  44.         shXL = Nothing
  45.  
  46.         appXL = Nothing
  47.  
  48.         Exit Sub
  49.  
  50.  
  51. Err_Handler:
  52.  
  53.         MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
  54.  
  55.  
  56.  
  57.  
  58.     End Sub
  59. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement