以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- excelvba请教 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=56944) |
-- 作者:hbhb -- 发布时间:2014/9/15 19:26:00 -- excelvba请教 Dim App As New MSExcel.Application Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(ProjectPath & "Attachments\\标准模板.xls") Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1) Dim Rg As MSExcel.Range Ws.UnProtect(Password:="hhh") ws.protect(Scenarios:= True) ws.protect(AllowFormattingCells:= True) ws.protect(AllowFormattingColumns:= True) ws.protect(AllowFormattingRows:= True) ws.protect(AllowInsertingRows:= True) ws.protect(AllowInsertingHyperlinks:= True) ws.protect(AllowDeletingColumns:= True) ws.protect(AllowDeletingRows:= True) ws.protect(AllowFormattingCells:= True) ws.protect(AllowFormattingCells:= True) ws.protect(AllowFormattingCells:= True) Ws.Protect(Password:="hhh") \'以密码保护 打开此excel表为何不能删除行,删除列? 而在excel上直接保护为何就可以?
|
-- 作者:有点甜 -- 发布时间:2014/9/15 19:29:00 -- 测试有效
Dim App As New MSExcel.Application Ws.UnProtect(Password:="hhh") wb.save |
-- 作者:hbhb -- 发布时间:2014/9/15 19:53:00 -- 测试过了,保护后不能删除行,删除列? |
-- 作者:有点甜 -- 发布时间:2014/9/15 20:05:00 -- 抱歉,看了一下,是要一起写的。单独设置,以最后一个为准
Dim App As New MSExcel.Application ws.protect(AllowDeletingRows:= True, AllowDeletingColumns:= True, Password:="hhh") wb.save |
-- 作者:hbhb -- 发布时间:2014/9/15 20:22:00 -- 苍天呀,大地呀,我可测试了整整一天呀,写帮助的是哪位老兄,我要请她喝68度的二哥头,如果不喝,我就朝他的眼睛里灌下去,用打火机在他嘴里点燃! |
-- 作者:hbhb -- 发布时间:2014/9/15 20:54:00 -- 问题又来了,模板生成后,又不能删除行,删除列了??????????? |
-- 作者:有点甜 -- 发布时间:2014/9/15 20:56:00 -- 生成报表以后,重新用vba打开设置一次 |
-- 作者:hbhb -- 发布时间:2014/9/15 21:20:00 -- Dim Book As New XLS.Book(ProjectPath & "Attachments\\标准模板.xls") Dim Sheet As XLS.Sheet Dim fl As String = ProjectPath & "Reports\\标准模板.xls" Book.Build() \'生成细节区 sheet = book.sheets(0) Dim App1 As New MSExcel.Application Dim Wb1 As MSExcel.WorkBook = App1.WorkBooks.Open(ProjectPath & "Attachments\\标准模板.xls") Dim Ws1 As MSExcel.WorkSheet = Wb1.WorkSheets(1) \'Dim Rg As MSExcel.Range \'Dim Rg1 As MSExcel.Range Ws1.UnProtect(Password:="hhh") ws1.protect(Contents:= True,Scenarios:= True,AllowFormattingCells:= True,AllowFormattingColumns:= True, _ AllowFormattingRows:= True,AllowInsertingRows:= True,AllowDeletingColumns:= True,AllowDeletingRows:= True, _ AllowInsertingHyperlinks:= True,Password:="hhh") wb1.save app1.quit Book.Save(fl) \'保存工作簿 Dim Proc As New Process \'打开工作簿 Proc.File = fl Proc.Start() 甜老大:以上哪里不对?
|
-- 作者:有点甜 -- 发布时间:2014/9/15 21:27:00 -- Dim Book As New XLS.Book(ProjectPath & "Attachments\\标准模板.xls") Dim App1 As New MSExcel.Application Dim Proc As New Process \'打开工作簿 |
-- 作者:hbhb -- 发布时间:2014/9/15 21:54:00 -- 谢谢!谢谢! |