Foxtable(狐表)用户栏目专家坐堂 → excelvba请教


  共有2983人关注过本帖树形打印复制链接

主题:excelvba请教

帅哥哟,离线,有人找我吗?
hbhb
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:5054 积分:13031 威望:0 精华:0 注册:2014/5/15 21:34:00
excelvba请教  发帖心情 Post By:2014/9/15 19:26:00 [只看该作者]

 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上直接保护为何就可以?

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/9/15 19:29:00 [只看该作者]

 测试有效

 

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("d:\test.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")  '以密码保护

wb.save
app.quit


 回到顶部
帅哥哟,离线,有人找我吗?
hbhb
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:5054 积分:13031 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By:2014/9/15 19:53:00 [只看该作者]

测试过了,保护后不能删除行,删除列?

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/9/15 20:05:00 [只看该作者]

抱歉,看了一下,是要一起写的。单独设置,以最后一个为准

 

Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("d:\test.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range

ws.protect(AllowDeletingRows:= True, AllowDeletingColumns:= True, Password:="hhh")

wb.save
app.quit


 回到顶部
帅哥哟,离线,有人找我吗?
hbhb
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:5054 积分:13031 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By:2014/9/15 20:22:00 [只看该作者]

苍天呀,大地呀,我可测试了整整一天呀,写帮助的是哪位老兄,我要请她喝68度的二哥头,如果不喝,我就朝他的眼睛里灌下去,用打火机在他嘴里点燃!

 回到顶部
帅哥哟,离线,有人找我吗?
hbhb
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:5054 积分:13031 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By:2014/9/15 20:54:00 [只看该作者]

问题又来了,模板生成后,又不能删除行,删除列了???????????

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/9/15 20:56:00 [只看该作者]

 生成报表以后,重新用vba打开设置一次


 回到顶部
帅哥哟,离线,有人找我吗?
hbhb
  8楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:5054 积分:13031 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By: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()


甜老大:以上哪里不对?

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2014/9/15 21:27:00 [只看该作者]

Dim Book As New XLS.Book(ProjectPath & "Attachments\标准模板.xls")
Dim Sheet As XLS.Sheet
Dim fl As String = ProjectPath & "Reports\标准模板.xls"
Book.Build() '生成细节区
Book.Save(fl) '保存工作簿

Dim App1 As New MSExcel.Application
Dim Wb1 As MSExcel.WorkBook = App1.WorkBooks.Open(fl)
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

Dim Proc As New Process '打开工作簿
Proc.File = fl
Proc.Start()


 回到顶部
帅哥哟,离线,有人找我吗?
hbhb
  10楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:狐神 帖子:5054 积分:13031 威望:0 精华:0 注册:2014/5/15 21:34:00
  发帖心情 Post By:2014/9/15 21:54:00 [只看该作者]

谢谢!谢谢!

 回到顶部
总数 18 1 2 下一页