VBA,编写了一个不能保存excel的代码,结果excel不能保存了不假,连代码也保存不了了,悲剧。。
如何可以保存VBA代码而不保存excel改动。PrivateSubWorkbook_BeforeSave(ByValSaveAsUIAsBoolean,CancelAsB...
如何可以保存VBA代码而不保存excel改动。
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not SaveAsUI Then MsgBox "本工作簿不能保存,只能另存为!": Cancel = True
End Sub 展开
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not SaveAsUI Then MsgBox "本工作簿不能保存,只能另存为!": Cancel = True
End Sub 展开
4个回答
展开全部
用代码保存,新建一个模块,内容如下,要保存时就运行以下代码
Public isForSave As Boolean
Private Sub SaveBook()
isForSave = True
ThisWorkbook.Save
isForSave = False
End Sub
ThisWorkbook代码改为:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not SaveAsUI And Not isForSave Then
MsgBox "本工作簿不能保存,只能另存为!"
Cancel = True
End If
End Sub
Public isForSave As Boolean
Private Sub SaveBook()
isForSave = True
ThisWorkbook.Save
isForSave = False
End Sub
ThisWorkbook代码改为:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
If Not SaveAsUI And Not isForSave Then
MsgBox "本工作簿不能保存,只能另存为!"
Cancel = True
End If
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我编写时也出现这问题,只能另存为其他名称,退出后再从文件夹里改回原来的文件名
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
debug cancel,TRUE改成FALSE
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询