stevennathaniel

Membuat Multiple Sheet Excel Secara Bersamaan

Jan 28th, 2016
80
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 Form10
  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 nomerSheet As Integer
  19.  
  20.  
  21.  
  22.     Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
  23.  
  24.         appXL = New Excel.Application
  25.  
  26.         wbXL = appXL.Workbooks.Open("D:\fileExcel\Latihan100.xlsx")
  27.  
  28.         appXL.Visible = True
  29.  
  30.         For i = 5 To 7
  31.  
  32.             nomerSheet = i
  33.  
  34.  
  35.             With wbXL
  36.  
  37.                 .Worksheets.Add(After:=.Worksheets(nomerSheet))
  38.  
  39.  
  40.             End With
  41.  
  42.         Next
  43.  
  44.  
  45.  
  46.         appXL.UserControl = True
  47.  
  48.         raXL = Nothing
  49.  
  50.         wbXL = Nothing
  51.  
  52.         shXL = Nothing
  53.  
  54.         appXL = Nothing
  55.  
  56.  
  57.         Exit Sub
  58.  
  59. Err_Handler:
  60.  
  61.         MsgBox(Err.Description, vbCritical, "Error: " & Err.Number)
  62.  
  63.     End Sub
  64. End Class
RAW Paste Data