ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 109|回复: 0

EXCEL2003转成EXCEL2013(或比2007更高版本)的代码、另外工作表加上保护密码

[复制链接]

TA的精华主题

TA的得分主题

发表于 2024-1-20 12:53 | 显示全部楼层 |阅读模式
本帖最后由 feiaoli 于 2024-1-20 13:20 编辑

1、EXCEL2003转成EXCEL2013(或比2007更高版本)的代码
2、另外工作表加上保护密码。
3、原始表格密码没有
4、想转换excel高版本的原因是:好多电脑不能用这个小程序

谢谢各位老师

  1. Sub 保存()
  2. 'ActiveSheet.Unprotect "1234" '解除工作表保护1234是保护密码
  3. Dim X As Integer '解除所有工作表保护
  4.       For X = 1 To Sheets.Count '解除所有工作表保护
  5.           Sheets(X).Unprotect '解除所有工作表保护
  6.       Next X '解除所有工作表保护
  7.      If Application.CountA(Sheets("excel预算单位项目资金支出计划申请书").Range("a4:f4")) < Sheets("excel预算单位项目资金支出计划申请书").Range("a4:f4").Count Then
  8.         Cancel = True
  9.         MsgBox "完善相关数据后再打印保存"
  10.      Else
  11. ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True '打印
  12. Sheets("excel预算单位项目资金支出计划申请书").Select
  13. lastrow = Sheets("excel预算单位项目资金支出计划数据库").Cells(Rows.Count, "a").End(3).Row + 1
  14. With Sheets("excel预算单位项目资金支出计划数据库")
  15.     .Cells(lastrow, 2) = [b2].Value
  16.     .Cells(lastrow, 3) = [E2].Value
  17.     .Cells(lastrow, 4) = [B3].Value
  18.     .Cells(lastrow, 5) = [D3].Value
  19.     .Cells(lastrow, 6) = [F3].Value
  20.     .Cells(lastrow, 7) = [B4].Value
  21.     .Cells(lastrow, 8) = [D4].Value
  22.     .Cells(lastrow, 9) = [f4].Value
  23.     .Cells(lastrow, 10) = Replace(Range("a5"), Chr(10), "") '[a5].Value
  24.     .Cells(lastrow, 11) = [H2].Value
  25.     .Cells(lastrow, 1) = [h1].Value
  26.      For n = 1 To 10
  27.        .Cells(lastrow, n + 11) = Cells(n + 12, "m")
  28.     Next n
  29. End With
  30.     Worksheets("excel预算单位项目资金支出计划申请书").[h1] = Left(Worksheets("excel预算单位项目资金支出计划申请书").[h1].Value, 1) & Format(Right(Worksheets("excel预算单位项目资金支出计划申请书").[h1].Value, 3) + 1, "20240000")
  31.     Worksheets("excel预算单位项目资金支出计划申请书").Range("e2:f2,b3,d3,f3,b4,d4,f4").ClearContents '清除选中单元格
  32.     Worksheets("excel预算单位项目资金支出计划申请书").Range("a5") = " "
  33.     Worksheets("excel预算单位项目资金支出计划申请书").[f4].Select
  34. Application.ScreenUpdating = True
  35.     End If
  36.     ThisWorkbook.Save
  37. 'ActiveSheet.Protect "1234" '工作表保护1234是保护密码
  38. Dim b As Integer '保护所有工作表
  39.       For b = 1 To Sheets.Count '保护所有工作表
  40.           Sheets(b).Protect '保护所有工作表
  41.       Next b '保护所有工作表
  42. End Sub
复制代码
  1. Sub 保存()
  2. Dim X As Integer '解除所有工作表保护
  3.       For X = 1 To Sheets.Count '解除所有工作表保护
  4.           Sheets(X).Unprotect '解除所有工作表保护
  5.       Next X '解除所有工作表保护
  6.      If Application.CountA(Sheets("excel项目申请审批单").Range("a2:a7")) < Sheets("excel项目申请审批单").Range("a2:a7").Count Then
  7.         Cancel = True
  8.         MsgBox "完善相关数据后再打印保存"
  9.      Else
  10. ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True '打印
  11. Sheets("excel项目申请审批单").Select
  12. lastrow = Sheets("excel项目申请审批单库").Cells(Rows.Count, "a").End(3).Row + 1
  13. With Sheets("excel项目申请审批单库")
  14.     .Cells(lastrow, 2) = [a2].Value
  15.     .Cells(lastrow, 3) = [a3].Value
  16.     .Cells(lastrow, 4) = [a4].Value
  17.     .Cells(lastrow, 5) = [a5].Value
  18.     .Cells(lastrow, 6) = [a6].Value
  19.     .Cells(lastrow, 7) = [a7].Value
  20.     .Cells(lastrow, 8) = [H2].Value
  21.     .Cells(lastrow, 1) = [h1].Value
  22.      For n = 1 To 10
  23.        .Cells(lastrow, n + 9) = Cells(n + 10, "m")
  24.     Next n
  25. End With
  26.     Worksheets("excel项目申请审批单").[h1] = Left(Worksheets("excel项目申请审批单").[h1].Value, 1) & Format(Right(Worksheets("excel项目申请审批单").[h1].Value, 3) + 1, "00000000")
  27.     'Worksheets("excel项目申请审批单").Range("a2:a5=0,a7=0").ClearContents '清除选中单元格
  28.     Worksheets("excel项目申请审批单").Range("a2") = " " '给单元格赋值
  29.     Worksheets("excel项目申请审批单").Range("a3") = " "
  30.     'Worksheets("excel项目申请审批单").Range("a4") = " "
  31.     Worksheets("excel项目申请审批单").Range("a5") = " "
  32.     Worksheets("excel项目申请审批单").Range("a7") = " "
  33.     Worksheets("excel项目申请审批单").Range("a8") = " "
  34.     Worksheets("excel项目申请审批单").[f4].Select
  35. Application.ScreenUpdating = True
  36.         End If
  37.     ThisWorkbook.Save
  38. Dim b As Integer '保护所有工作表
  39.       For b = 1 To Sheets.Count '保护所有工作表
  40.           Sheets(b).Protect '保护所有工作表
  41.       Next b '保护所有工作表
  42. End Sub
复制代码


excelhome.rar

32.3 KB, 下载次数: 3

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-5-8 00:51 , Processed in 0.033555 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表