langtuchungtinh360
Thành viên đã dừng hoạt động
- Tham gia
- 7/10/13
- Bài viết
- 1,062
- Được thích
- 334
em có làm 1 add ins để hỗ trợ cho công việc
nhưng có một lỗi là sau khi tạo xong các sheet cần thiết
đến khi chọn 1 sheet bất kỳ thì báo lỗi không chạy được code
cụ thể trong addins em viết
1. chọn vào "Tạo mới" trên Ribbon sẽ tạo 1 file mới
2. sau khi tạo xong thì có thể chọn sang 1 sheet bất kỳ
ví dụ : NTVLDV
thì báo lỗi ngay dòng Updatexx
Trong khi Sub Updatexx đã có tại Module Update của addins
mong mọi ngời giúp đỡ
Do kiến thức không đến đâu nên em có suy nghĩ là phải viết code Updatexx ngay trên file hiện hành luôn thì mới chạy được
em có tham khảo #1
http://www.giaiphapexcel.com/forum/showthread.php?80149-Tự-động-chèn-code-vào-sheet-của-1-File-Excel
nhưng không thể chạy được code này
Đã làm bước này rồi mà vẫn báo lỗi không chạy được
Chú ý: Để chèn được Module thì phải vào Tools, tìm và chọn mục Microsoft Visual Basic for Appliations extensibility 5.3
Hoặc khi viết code đến dòng ActiveWorkbook.VBProject.VBComponents.Add(vbext_ct _StdModule) thì Excel sẽ tự động hỏi mình có muốn chọn mục này hay không.
nhưng có một lỗi là sau khi tạo xong các sheet cần thiết
đến khi chọn 1 sheet bất kỳ thì báo lỗi không chạy được code
cụ thể trong addins em viết
1. chọn vào "Tạo mới" trên Ribbon sẽ tạo 1 file mới
2. sau khi tạo xong thì có thể chọn sang 1 sheet bất kỳ
ví dụ : NTVLDV
thì báo lỗi ngay dòng Updatexx
Trong khi Sub Updatexx đã có tại Module Update của addins
mong mọi ngời giúp đỡ
Do kiến thức không đến đâu nên em có suy nghĩ là phải viết code Updatexx ngay trên file hiện hành luôn thì mới chạy được
em có tham khảo #1
http://www.giaiphapexcel.com/forum/showthread.php?80149-Tự-động-chèn-code-vào-sheet-của-1-File-Excel
nhưng không thể chạy được code này
Mã:
[COLOR=#0000BB][FONT=monospace]Sub Add_Module_and_Code[/FONT][/COLOR][COLOR=#007700][FONT=monospace]()
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Dim CodeLines [/FONT][/COLOR][COLOR=#007700][FONT=monospace]As [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Long[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]VBComp
Set VBComp [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]ActiveWorkbook[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]VBProject[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]VBComponents[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Add[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]vbext_ct_StdModule[/FONT][/COLOR][COLOR=#007700][FONT=monospace])
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]With ActiveWorkbook[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]VBProject[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]VBComponents[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]VBComp[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Name[/FONT][/COLOR][COLOR=#007700][FONT=monospace]).[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]CodeModule
CodeLines [/FONT][/COLOR][COLOR=#007700][FONT=monospace]= .[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]CountOfLines [/FONT][/COLOR][COLOR=#007700][FONT=monospace]+ [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]1
[/FONT][/COLOR][COLOR=#007700][FONT=monospace].[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]InsertLines CodeLines[/FONT][/COLOR][COLOR=#007700][FONT=monospace], [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]_
[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"Sub Add_Module_and_Code" [/FONT][/COLOR][COLOR=#007700][FONT=monospace]& [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Chr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]13[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) & [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]_
[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]" msgbox ""Code Created"" " [/FONT][/COLOR][COLOR=#007700][FONT=monospace]& [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]Chr[/FONT][/COLOR][COLOR=#007700][FONT=monospace]([/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]13[/FONT][/COLOR][COLOR=#007700][FONT=monospace]) & [/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]_
[/FONT][/COLOR][COLOR=#DD0000][FONT=monospace]"End Sub"
[/FONT][/COLOR][COLOR=#0000BB][FONT=monospace]End With
End Sub [/FONT][/COLOR]
Đã làm bước này rồi mà vẫn báo lỗi không chạy được
Chú ý: Để chèn được Module thì phải vào Tools, tìm và chọn mục Microsoft Visual Basic for Appliations extensibility 5.3
Hoặc khi viết code đến dòng ActiveWorkbook.VBProject.VBComponents.Add(vbext_ct _StdModule) thì Excel sẽ tự động hỏi mình có muốn chọn mục này hay không.
File đính kèm
Lần chỉnh sửa cuối: