stevennathaniel

If Then yang Sama Dengan VBA di MS Excel

Jan 26th, 2016
82
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.  
  6. Public Class Form5
  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.     Dim i As Integer
  17.  
  18.     Dim result As String
  19.  
  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.         shXL = wbXL.Worksheets("Sheet2")
  28.  
  29.         appXL.Visible = True
  30.  
  31.  
  32.         i = shXL.Range("A1").Value
  33.  
  34.         If i >= 6 Then result = "pass"
  35.  
  36.         shXL.Range("B1").Value = result
  37.  
  38.  
  39.         appXL.UserControl = True
  40.  
  41.         raXL = Nothing
  42.  
  43.         wbXL = Nothing
  44.  
  45.         shXL = Nothing
  46.  
  47.         appXL = Nothing
  48.  
  49.         Exit Sub
  50.  
  51.  
  52. Err_Handler:
  53.  
  54.         MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
  55.  
  56.  
  57.     End Sub
  58. End Class
RAW Paste Data