Chào các bác, mình có một vấn đề cần trợ giúp như sau. Mình có tạo một nút enable/disable theo sự tồn tại của sheet, nhưng vấn đề là nút này chỉ hoạt động khi thoát excel và vào lại, mình muốn nó load ngay khi thêm hoặc xoá sheet "DU TOAN" có được không
(Nút "Tổng hợp" (bị mờ) sẽ được bật khi tồn tại sheet "DU TOAN" và bị làm mờ khi không có sheet này)
(Khi ở trạng thái disable sẽ bị làm mờ (khoanh đỏ))
(Khi thoát excel và khởi động lại, nút ở trạng thái enable và hiển thị bình thường như các nút khác)
Đây là code XML:
Đây là code VBA:
Bạn cần đăng nhập để thấy hình ảnh
(Nút "Tổng hợp" (bị mờ) sẽ được bật khi tồn tại sheet "DU TOAN" và bị làm mờ khi không có sheet này)
Bạn cần đăng nhập để thấy hình ảnh
(Khi ở trạng thái disable sẽ bị làm mờ (khoanh đỏ))
Bạn cần đăng nhập để thấy hình ảnh
(Khi thoát excel và khởi động lại, nút ở trạng thái enable và hiển thị bình thường như các nút khác)
Đây là code XML:
XML:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="onRibbonLoad">
<ribbon>
<tabs>
<tab id="VBA_Ribbon" label="CV.DOTA">
<group id="survey" label="Xử lý khảo sát">
<button id="S_DOITENCOC"
label="Đổi tên cọc"
size="large"
onAction="BTN_DOITENCOC"
supertip="Đổi tên cọc nhanh theo các quy tắc có sẵn"
imageMso="ReplaceDialog" />
<button id="S_LOAICOC"
label="Loại bớt cọc"
size="large"
onAction="BTN_LOAICOC"
supertip="Loại bớt cọc phù hợp với bước nghiên cứu khả thi"
imageMso="CellsDelete" />
<box id="B_BINHSAI" boxStyle="vertical">
<menu id="M_BINHSAI_DC" label="Bình sai độ cao" imageMso="ExportTextFile" >
<button id="S_DCHH"
label="Tạo tệp bình sai độ cao HHmaps"
onAction="BTN_DCHH"
supertip="Tạo tệp bình sai độ cao HHmaps từ số liệu XYH" />
<menuSeparator id="separator_dc" />
<button id="S_DCDP"
label="Tạo tệp bình sai độ cao DPSurvey"
onAction="BTN_DCDP"
supertip="Tạo tệp bình sai độ cao DPSurvey từ số liệu XYH" />
</menu>
<menu id="M_BINHSAI_MB" label="Bình sai mặt bằng" imageMso="ExportTextFile" >
<button id="S_MBHH"
label="Tạo tệp bình sai mặt bằng HHmaps"
onAction="BTN_MBHH"
supertip="Tạo tệp bình sai mặt bằng HHmaps từ số liệu XYH" />
<menuSeparator id="separator_mb" />
<button id="S_MBDP"
label="Tạo tệp bình sai mặt bằng DPSurvey"
onAction="BTN_MBDP"
supertip="Tạo tệp bình sai mặt bằng DPSurvey từ số liệu XYH" />
</menu>
<button id="S_XULYRTK"
label="Xử lý số liệu RTK"
onAction="BTN_XULYRTK"
supertip="Định dạng lại số liệu xuất từ RTK của một số máy"
imageMso="CommaStyle" />
</box>
</group>
<group id="tienich" label="Tiện ích">
<button id="S_GOPFILE"
label="Gộp nhiều File"
size="large"
onAction="BTN_GOPFILE"
supertip="Gộp nhiều file thành một file duy nhất"
imageMso="GetPowerQueryMerge" />
<button id="S_MUCLUC"
label="Tạo mục lục"
size="large"
onAction="BTN_MUCLUC"
supertip="Tạo mục lục nhanh từ các sheet trong file excel"
imageMso="BulletsAndNumberingBulletsDialog" />
<button id="S_SENDMAIL"
label="Gửi Email nhanh"
size="large"
onAction="BTN_SENDEMAIL"
supertip="Gửi email nhanh ngay trên excel"
imageMso="ContactCardSendEmail" />
<button id="S_CHIAH"
label="Chia cọc theo H"
size="large"
onAction="BTN_CHIAH"
supertip="Chia khoảng cách cộng dồn theo cọc H"
imageMso="OutlineSubtotals" />
</group>
<group id="UDF" label="Function">
<menu id="M_function" label="Hàm tự định nghĩa" imageMso="FunctionWizard" size="large" >
<button id="S_DOCSOTHANHCHU"
label="VND(number)"
supertip="Đọc số tiền thành chữ"
imageMso="AccountingFormat" />
<button id="S_TINHDIENGIAI"
label="EVAL(text)"
supertip="Tính kết quả từ diễn giải"
imageMso="Calculator" />
<button id="S_SUMBYCOLOR"
label="SUMBYCOLOR(sum_range,cell_color)"
supertip="Tính tổng các ô theo màu"
imageMso="AutoSum" />
<button id="S_COUNTBYCOLOR"
label="COUNTBYCOLOR(count_range,cell_color)"
supertip="Đếm tổng số ô theo màu"
imageMso="AppointmentColorDialog" />
<button id="S_SHEETNAME"
label="SHEETNAME(range)"
supertip="Lấy tên sheet đang được mở"
imageMso="HeaderFooterSheetNameInsert" />
</menu>
</group>
<group id="bangtinh" label="Bảng tính">
<button id="S_CHENMAU"
label="Chèn bảng tính mẫu"
size="large"
onAction="BTN_CHENMAU"
supertip="Chèn bảng tính theo mẫu có sẵn"
imageMso="TableExcelSpreadsheetInsert" />
<button id="S_BANGTONGHOP"
label="Tạo bảng tổng hợp"
size="large"
onAction="BTN_BANGTONGHOP"
supertip="Tạo bảng tổng hợp tất cả các sheet"
imageMso="QueryShowTable"
getEnabled="onGetEnabled" />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
Mã:
Private rbIRibbonUI As IRibbonUI
Private rbVisible As Boolean
Private Sub onRibbonLoad(ribbon As IRibbonUI)
Set rbIRibbonUI = ribbon
rbVisible = False
rbIRibbonUI.Invalidate
End Sub
Sub onGetEnabled(control As IRibbonControl, ByRef enabled)
Dim wb As Workbook
Dim ws As Worksheet
On Error Resume Next
Set wb = ActiveWorkbook
Set ws = wb.Sheets("DU TOAN")
If ws Is Nothing Then
enabled = False
Else
enabled = True
End If
End Sub
Sửa lần cuối: