我正在尝试使用Veryhidden强制用户启用宏来维护工作簿的安全性。
除了用户抱怨缺少对话框以询问是否要保存或关闭时,该方法非常有用。
我以msgbox的形式添加了保存/不保存功能,但这打开了一个违反安全性的特殊情况:
即,如果用户打开文件,启用宏,跳过启动画面,使用保存功能保存工作簿,然后关闭而不保存,则下次打开工作簿时,不会强制用户启用宏。
我试图通过设置以下代码在保存时运行来解决此问题(在保存之前我没有运气,因为在代码运行后它又保存了,这违反了代码的要点),但是此代码似乎会产生由保存触发的无限循环。我尝试在开始时进行检查以检查状态是否已保存,但是由于宏在保存后运行,因此对于宏来说始终是真实状态。
类似地,我尝试在底部添加一个检查以查看其是否已保存以及是否保存,然后退出该子例程,但是代码从没有走过这么远,因为它在保存时会再次触发。
有人有什么想法吗? (下面的代码)
import React, { Component } from 'react';
class App extends Component {
constructor(props)
{
super(props);
this.state = {
items: [],
isLoaded: false,
}
}
componentDidMount()
{
fetch('API which i cant display but works 100% fine . please ignore')
.then(res => res.json())
.then(json => {
this.setState({
isLoaded: true,
items: json,
})
})
.catch(e => { console.log("error: ",e) });
}
render()
{
var { isLoaded, items } = this.state;
console.log("Hello ", items);
if (!isLoaded)
{
return <div>Loading..</div>
}
else {
return (
<div className="App">
Id : item.id
<ul>
{items.map(item => (
<li key={item.id}>
Name: {item.name}
Email: {item.email}
</li>
))};
</ul>
</div>
);
}
}
}
export default App;
答案 0 :(得分:1)
避免无限的触发循环:
'Step 7: Save the workbook
Application.EnableEvents = False
ActiveWorkbook.Save
Application.EnableEvents = True
答案 1 :(得分:0)
略有不同的策略:
Workbook_BeforeSave
取消隐藏“开始”工作表并隐藏所有将触发的其他人Workbook_AfterSave
隐藏“开始”并取消隐藏所有其他工作表,并且Workbook_Open
隐藏“开始”并取消隐藏所有其他工作表。代码:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Dim ws As Worksheet
Application.ScreenUpdating = False 'stops flicker and improves speed
Sheets("START").Visible = xlSheetVisible
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Start" Then
ws.Visible = xlVeryHidden
End If
Next ws
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_AfterSave(ByVal Success As Boolean)
Dim ws As Worksheet
Application.ScreenUpdating = False 'stops flicker and improves speed
For Each ws In ThisWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
Sheets("START").Visible = xlVeryHidden
Application.ScreenUpdating = True
End Sub
Private Sub Workbook_Open()
Dim ws As Worksheet
Application.ScreenUpdating = False 'stops flicker and improves speed
For Each ws In ThisWorkbook.Worksheets
ws.Visible = xlSheetVisible
Next ws
Sheets("START").Visible = xlVeryHidden
Application.ScreenUpdating = True
End Sub