个人工作簿未运行宏。

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

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:

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

The error is

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

Sub make_buttons_appear_onhotkey()

Dim ws As Worksheet
Dim pwb As Worksheet

Dim shape1 As Shape
Dim shape2 As Shape
Dim shape3 As Shape
Dim shape4 As Shape

Dim shapetop As Long
Dim shapeleft As Long
Dim shapeheight As Long
Dim shapewidth As Long

Dim shapetop2 As Long
Dim shapeleft2 As Long
Dim shapeheight2 As Long
Dim shapewidth2 As Long

Set ws = ActiveWorkbook.ActiveSheet

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

Set shape1 = pwb.Shapes("Button 1")
shapetop = shape1.Top
shapeleft = shape1.Left
shapeheight = shape1.Height
shapewidth = shape1.Width
shape1.Copy
ws.Paste
Set shape3 = ws.Shapes("Button 1")
shape3.Top = shapetop
shape3.Left = shapeleft
shape3.Height = shapeheight
shape3.Width = shapewidth

Set shape2 = pwb.Shapes("Button 2")
shapetop2 = shape2.Top
shapeleft2 = shape2.Left
shapeheight2 = shape2.Height
shapewidth2 = shape2.Width
shape2.Copy
ws.Paste
Set shape4 = ws.Shapes("Button 2")
shape4.Top = shapetop2
shape4.Left = shapeleft2
shape4.Height = shapeheight2
shape4.Width = shapewidth2

Application.OnKey "{ESC}", "make_buttons_disappear_onclick"

Range("A1").Select

End Sub

Sub make_buttons_disappear_onclick()

Dim ws As Worksheet
Set ws = ActiveWorkbook.ActiveSheet

ws.Shapes("Button 1").Delete
ws.Shapes("Button 2").Delete

Application.OnKey "{ESC}"

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:

确定