个人工作簿未运行宏。

huangapple go评论106阅读模式
英文:

Personal workbook isn't running macros

问题

I am setting up a new computer and created a Personal workbook. The workbook has code that is called with a hotkey that makes buttons appear. I put the Personal workbook in my XLSTART folder.

我正在设置一台新电脑并创建了一个个人工作簿。该工作簿包含一个通过热键调用的代码,用于显示按钮。我将个人工作簿放在XLSTART文件夹中。

I have two computers, both with the same code. One of them works and the other doesn't. I have WinMerge to compare the two, and they are the same.

我有两台电脑,都使用相同的代码。其中一台正常工作,另一台不工作。我使用WinMerge比较了两台电脑,它们是相同的。

There is a worksheet called "Sheet1" in my personal workbook that has "Button 1" and "Button 2."

我的个人工作簿中有一个名为“Sheet1”的工作表,其中包含“Button 1”和“Button 2”。

The line that errors is:

出错的代码行是:

Set pwb = Workbooks("Personal").Worksheets("Sheet1")

错误是

Runtime error '9': Subscript out of range

运行时错误 '9': 下标超出范围

(Note: I've provided translations for the code and error message as requested, but please do not ask me to translate additional content or answer translation-related questions.)

英文:

I am setting up a new computer and created a Personal workbook. The workbook has code that is called with a hotkey that makes buttons appear. I put the Personal workbook in my XLSTART folder.

I have two computers, both with the same code. One of them works and the other doesn't. I have WinMerge to compare the two, and they are the same.

There is a worksheet called "Sheet1" in my personal workbook that has "Button 1" and "Button 2."

The line that errors is:

  1. Set pwb = Workbooks("Personal").Worksheets("Sheet1")

The error is

>Runtime error '9': Subscript out of range"

  1. Sub make_buttons_appear_onhotkey()
  2. Dim ws As Worksheet
  3. Dim pwb As Worksheet
  4. Dim shape1 As Shape
  5. Dim shape2 As Shape
  6. Dim shape3 As Shape
  7. Dim shape4 As Shape
  8. Dim shapetop As Long
  9. Dim shapeleft As Long
  10. Dim shapeheight As Long
  11. Dim shapewidth As Long
  12. Dim shapetop2 As Long
  13. Dim shapeleft2 As Long
  14. Dim shapeheight2 As Long
  15. Dim shapewidth2 As Long
  16. Set ws = ActiveWorkbook.ActiveSheet
  17. Set pwb = Workbooks("Personal").Worksheets("Sheet1")
  18. Set shape1 = pwb.Shapes("Button 1")
  19. shapetop = shape1.Top
  20. shapeleft = shape1.Left
  21. shapeheight = shape1.Height
  22. shapewidth = shape1.Width
  23. shape1.Copy
  24. ws.Paste
  25. Set shape3 = ws.Shapes("Button 1")
  26. shape3.Top = shapetop
  27. shape3.Left = shapeleft
  28. shape3.Height = shapeheight
  29. shape3.Width = shapewidth
  30. Set shape2 = pwb.Shapes("Button 2")
  31. shapetop2 = shape2.Top
  32. shapeleft2 = shape2.Left
  33. shapeheight2 = shape2.Height
  34. shapewidth2 = shape2.Width
  35. shape2.Copy
  36. ws.Paste
  37. Set shape4 = ws.Shapes("Button 2")
  38. shape4.Top = shapetop2
  39. shape4.Left = shapeleft2
  40. shape4.Height = shapeheight2
  41. shape4.Width = shapewidth2
  42. Application.OnKey "{ESC}", "make_buttons_disappear_onclick"
  43. Range("A1").Select
  44. End Sub
  45. Sub make_buttons_disappear_onclick()
  46. Dim ws As Worksheet
  47. Set ws = ActiveWorkbook.ActiveSheet
  48. ws.Shapes("Button 1").Delete
  49. ws.Shapes("Button 2").Delete
  50. Application.OnKey "{ESC}"
  51. End Sub

答案1

得分: 0

Default file location in File->Options->Save should be
drive:\fullpath\XLStart, and in the Trusted Location in Trust Center.
Subscript out of range in this case means that a file with the given name is
not found in the directories where Excel looks for it.

英文:

What is the Default file location in File->Options->Save. It should be
drive:\fullpath\XLStart and in the Trusted Location in Trust Center.
Subscript out of range in this case means that a file with the given name is
not found in the directories, where Excel look for.

huangapple
  • 本文由 发表于 2023年5月18日 09:05:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277118.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定