Excel 2010 宏与按钮的乐趣

发布于 2024-11-28 07:11:02 字数 248 浏览 0 评论 0原文

好的,我正在创建一个电子表格,该电子表格可以由其他用户编辑,但否则会被锁定。我希望做的是创建 3 个按钮。 “What If”、“Exit What if”和“Reset”

“What if”将允许用户输入数据。 “Exit What if”将允许用户退出输入模式并恢复到默认状态。文档。 然后“重置”将允许用户停留在“假设”状态,但将所有值重置为默认值。

然后我希望“如果”按钮出现在左侧的某个位置,但是当您单击它时,它会被“退出”和“重置”取代

Ok so I am creating a spreadsheet that can be edited by another user but locked otherwise. What I am hoping to do is create 3 buttons. "What If" "Exit What if" and "Reset"

"What if" will allow for the user to input data.
"Exit what if" will allow for the user to exit the input mode and revert back to the default. document.
Then "Reset" will allow for the user stay in "What if" but reset all the values to default.

Then I want the button "What if" to appear somewhere up in the left but when you click it, its replaced by "Exit" and "Reset"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆一缕阳光ご 2024-12-05 07:11:02

我建议你多解释一下你的问题,但到目前为止我可以推断你有以下问题:

  • 有一个包含公式和数据锁定的 Excel 工作表。
  • 提供编辑页面,但不保存更改,作为对数据的“查阅”。

我主要可以提供以下服务:

  • 创建一个备份表,用于保存您的基本页面
  • 解锁该表以进行编辑。
  • 如果退出编辑,则将备份中的数据恢复到主表中。
  • 如果重置编辑,请执行与退出相同的过程并再次解锁数据。 (对于如何绘制代码流,复制的工作表已锁定其数据)

这将导致以下代码:

Sub BackUpData() 'this will be linked to you "what if" button
    Sheets("Data_Sheet").Select 'select shhet with data, just in case
    Range("A1:M56").Select ' range of your important data in your excel sheet
    Cells.Select
    Selection.Copy
    Sheets("BackUp_Sheet").Select
    Range("A1").Select     'lets paste the data in the same positión
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Sheets("Data_Sheet").Select
End Sub

这会复制数据和公式,在不破坏数据源的情况下复制图表是另一个问题,也许您可​​以详细阐述这个问题。有图表吗?

Sub RestoreData() 'this will be linked to you "Reset" and "Exit" button
    Sheets("BackUp_Sheet").Select 'select shhet with data, just in case
    Range("A1:M56").Select ' range of your important data in your excel sheet
    Cells.Select
    Selection.Copy
    Sheets("Data_Sheet").Select
    Range("A1").Select     'lets paste the data in the same positión
    ActiveSheet.Paste
    Application.CutCopyMode = False
End Sub

通常的改进空间:

  • 动态选择范围,但不要选择所有工作表,因为可能会出现内存问题。 (当我尝试在我的笔记本电脑中复制 excel 2007 的所有单元格时,我耗尽了资源:P)。
  • 使用Application.ScreenUpdating消除闪烁。
  • 我还没有检查当 *backup_Sheet* 隐藏时这是否有效。

另一个问题是解锁工作表中的数据。

Sub UnlockMySheet()
        'password here won`t protect the business logic or the code from prying eyes, just the user from themselves
        ActiveWorkbook.Unprotect 
        ActiveSheet.Unprotect
        Range("D9,B13").Select ' select the editable cells
        Selection.Locked = False
        Selection.FormulaHidden = False
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
        ActiveSheet.EnableSelection = xlUnlockedCells
        ActiveWorkbook.Protect Structure:=True, Windows:=True
End Sub

通常的改进空间:

  • 也许我忘记了保护协议,我只是将页面保持原样。 (抱歉没有时间证明这个代码)。
  • 来自 stackoverflow 集体思想的建议。

也就是说,现在

I suggest you to explain a little more you question, but so far for what I can infere you have the folloing issuse:

  • have a excel sheet with formulae and data locked.
  • offer edit the page, but no save the changes, as "a consult" to the data.

I can primarily offer the following:

  • Create a backup sheet where your save you base page
  • Unlock the sheet for editing.
  • if you exit the editing, restore the data from the backup to the main sheet.
  • if you reset the editing, do the same procedure as exit plus unlock again the data. (for how it was charted the code flow, the copied sheet has his data locked)

This will result in the followin code:

Sub BackUpData() 'this will be linked to you "what if" button
    Sheets("Data_Sheet").Select 'select shhet with data, just in case
    Range("A1:M56").Select ' range of your important data in your excel sheet
    Cells.Select
    Selection.Copy
    Sheets("BackUp_Sheet").Select
    Range("A1").Select     'lets paste the data in the same positión
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Sheets("Data_Sheet").Select
End Sub

This make a copy of the data and the formulas, copying charts without breaking his datasource is another problem, maybe your can elabore on this matter. Have any charts?

Sub RestoreData() 'this will be linked to you "Reset" and "Exit" button
    Sheets("BackUp_Sheet").Select 'select shhet with data, just in case
    Range("A1:M56").Select ' range of your important data in your excel sheet
    Cells.Select
    Selection.Copy
    Sheets("Data_Sheet").Select
    Range("A1").Select     'lets paste the data in the same positión
    ActiveSheet.Paste
    Application.CutCopyMode = False
End Sub

Usual room for improvement:

  • Dinamicaly select the range, but no select all the sheet, because memory isssuses may arise. (I run out of resources when try to copy all the cell of excel 2007 in my laptop :P).
  • Remove flicker with Application.ScreenUpdating.
  • I haven`t check if this work when the *backup_Sheet* is hidden.

The other isssuse is unlock the data in the sheet.

Sub UnlockMySheet()
        'password here won`t protect the business logic or the code from prying eyes, just the user from themselves
        ActiveWorkbook.Unprotect 
        ActiveSheet.Unprotect
        Range("D9,B13").Select ' select the editable cells
        Selection.Locked = False
        Selection.FormulaHidden = False
        ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
        ActiveSheet.EnableSelection = xlUnlockedCells
        ActiveWorkbook.Protect Structure:=True, Windows:=True
End Sub

Usual room for improvement:

  • Maybe I forgot the protect protocol and I`m just leaving the page exactly as it was. (sorry no time to proof this code).
  • Sugestion from stackoverflow collective mind.

and that is, for now

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文