Excel VBA – 保存前禁用表单

我在Excel 2010中创build了一个简单的电子表格,其中包含随电子表格打开而加载的表单。 员工填写所需的表单数据,并使用SaveAs方法按下“保存”buttonmacros。

我的问题是,如果有可能禁用保存的副本中的窗体? 原因是我们想避免在我们的簿记部门打开副本审查数据时加载表格。

澄清这是我的vba代码是如何

Sub SaveAsButton() Dim applicationUserName As String Dim saveLocation As String Dim fileName As String Dim weekNo As String Dim year As String weekNo = ThisWorkbook.Sheets("Service").Range("M4").Value Debug.Print (weekNo) year = ThisWorkbook.Sheets("Service").Range("R4").Value Debug.Print (year) applicationUserName = Application.UserName Debug.Print (applicationUserName) saveLocation = "w:\Service Users\" & applicationUserName & "\Service\" Debug.Print (saveLocation) fileName = "Service" & "-" & weekNo & "-" & year & "-" & applicationUserName Debug.Print (fileName) fileName = Replace(fileName, " ", "") Debug.Print (fileName) ThisWorkbook.SaveAs (saveLocation & fileName) End Sub 

谢谢。

如果在最终工作簿中不需要任何代码,则可以简单地另存为.xlsx,从而删除所有的vb组件

您可能需要使用CustomProperties

首先,创build一个CustomProperty

 ActiveWorkbook.CustomDocumentProperties.Add "Saved", False, msoPropertyTypeNumber, 0 

当用户保存表单时,将CustomProperty的值更改为1 (将以下代码添加到SaveAsButton() ):

 ActiveWorkbook.CustomDocumentProperties("Saved").Value = 1 

如果ActiveWorkbook.CustomDocumentProperties("Saved").Value = 0 ,打开表单的方法添加一个检查。