stevennathaniel

Excel: Berhasil Membuat Tombol Untuk Menutup Excel

Feb 9th, 2016
90
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 Form7
  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.  
  16.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  17.  
  18.         'Start Excel and get Application Object
  19.         appXL = CreateObject("Excel.Application")
  20.  
  21.         appXL.Visible = True
  22.  
  23.         ' Add a new workbook
  24.  
  25.         wbXL = appXL.Workbooks.Add
  26.  
  27.  
  28.  
  29.         'shXL = wbXL.Sheets("Sheet2")
  30.  
  31.         ' shXL.Activate()
  32.  
  33.         'appXL.UserControl = True
  34.  
  35.         'raXL = Nothing
  36.  
  37.         'wbXL = Nothing
  38.  
  39.         'shXL = Nothing
  40.  
  41.         'appXL = Nothing
  42.  
  43.         Exit Sub
  44.  
  45. Err_Handler:
  46.  
  47.         MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
  48.  
  49.  
  50.     End Sub
  51.  
  52.     Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
  53.  
  54.         raXL = Nothing
  55.  
  56.         shXL = Nothing
  57.  
  58.         wbXL = Nothing
  59.  
  60.         appXL.Quit()
  61.  
  62.         appXL = Nothing
  63.  
  64.     End Sub
  65. End Class
RAW Paste Data