Video hướng dẫn cơ bản tạo addin xll bằng ngôn ngữ VBnet

  • Thread starter Deleted member 1294
  • Ngày gửi
D

Deleted member 1294

Guest
Bài 1: Tạo nút bấm trên Ribbon
Trong video ở bài 1 sau khi tạo project các bạn được class1.vb và file có đuôi .dna
-Code lệnh cần thực thi trong class1:
Mã:
Imports System.Runtime.InteropServices 
Imports ExcelDna.Integration.CustomUI
<ComVisible(True)>'cần thiết để hiện nút bấm
Public Class Class1
    Inherits ExcelRibbon'cần thiết để hiện nút bấm
'lệnh thực hiện khi nhấn nút trên ribbon
    Public Sub OnButtonPressed(control As IRibbonControl)
        MsgBox("Chào mừng đến với TuhocVBA.net", vbInformation)
    End Sub
End Class
-CustomUI để trong file đuôi dna:
Mã:
<CustomUI>
    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
              xmlns:x="khaibao">
      <ribbon>
        <tabs>
          <tab id="idtab" label="Hello">
            <group idQ="x:idQ" label="TuhocVBA.net">
              <button id="C1" label="clock" size="large"
                imageMso="StartAfterPrevious" onAction="OnButtonPressed" />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
  </CustomUI>
-Built project bạn sẽ thấy nút bấm xuất hiện như hình
Bạn cần đăng nhập để thấy hình ảnh

-Project mẫu:
 
D

Deleted member 1294

Guest
Bài 2: Show 1 Form
-Tạo một form1 bằng cách click chuột phải vào tên Project chọn như hình
Bạn cần đăng nhập để thấy hình ảnh

Trong class1:
Mã:
Imports ExcelDna.Integration.CustomUI
Imports System.Runtime.InteropServices
<ComVisible(True)>
Public Class Class1
    Inherits ExcelRibbon
    Dim fr1 As New Form1 'biến fr1 như Form1
    Public Sub OnButtonPressed(control As IRibbonControl)
        fr1.ShowDialog()'show Form1
    End Sub
End Class
-Phần CustomUI mình không nhắc lại ở bài này !
-Video chi tiết:
Bạn cần đăng nhập để thấy đa phương tiện
-Project mẫu:
 
D

Deleted member 1294

Guest
Bài 3: Lấy tên workbook active, worksheet active và ghi giá trị tới cell
Mã:
Imports ExcelDna.Integration.CustomUI
Imports System.Runtime.InteropServices
Imports ExcelDna.Integration
<ComVisible(True)>
Public Class Class1
    Inherits ExcelRibbon
    Dim app, wb, ws As Object
    Public Sub OnButtonPressed(control As IRibbonControl)
        thongtin()
    End Sub
    Private Sub thongtin()
        app = ExcelDnaUtil.Application 'khai bao doi tuong me cua excel
        wb = app.activeworkbook
        ws = app.activesheet
        ws.range("A1") = "TuhocVBA.net" 'ghi gia tri toi A1 của activesheet
        MsgBox(wb.name & " and " & ws.name) 'lay ten activeworkbook  va activesheet.
    End Sub
End Class
Project mẫu:
 
Top