vba - my vba "object" wont move according to my code
问题描述
Sub macro1()
rep_count = 0
Do
DoEvents
rep_count = rep_count + 1
Sheet1.Shapes("rectangle").Left = rep_count
Sheet1.Shapes("rectangle").Top = rep_count
Sheet1.Shapes("rectangle").Height = rep_count
Sheet1.Shapes("rectangle").Width = rep_count
timeout (0.01)
Loop Until rep_count = 300
End Sub
Sub timeout()
start_time = Timer
Do
DoEvents
Loop Until (Timer - start_time) >= duration_ms
End Sub
the error keep saying "the error
解决方案
You are passing an argument into the timeout sub procedue that is not in the declaration.
Sub timeout(duration_ms as double) '<~~ pass parameter in here
dim start_time as double
start_time = Timer
Do
DoEvents
Loop Until (Timer - start_time) >= duration_ms
End Sub
Be careful that you do not use this as time crosses midnight. Timer is the number of seconds (and milliseconds) past midnight and resets to zero at midnight.
You can retrieve the shape's name by selecting it and passing this request to the VBE's Immediate window. ?Selection.ShapeRange.name
Use ActiveSheet or Worksheets("sheet1") to reference the shape by name, not the worksheet's codename.
Sub macro1()
Dim rep_Count As Long
rep_Count = 0
Do
DoEvents
rep_Count = rep_Count + 1
'With ActiveSheet.Shapes("Rectangle 1")
With Worksheets("sheet1").Shapes("Rectangle 1")
.Left = rep_Count
.Top = rep_Count
.Height = rep_Count
.Width = rep_Count
End With
timeout (0.01)
Loop Until rep_Count = 300
End Sub
推荐阅读
- java - 有没有更好的比较日期的方法
- c++ - 函数中的while循环上的“)”标记错误之前的预期主表达式
- asp.net-mvc - 尝试打开 DBF 文件的 OLE DB 异常:VFPOLEDB.4 提供程序未在本地计算机上注册
- ios - 在我的 mac OS Big Sur v11.0 中运行 docker 时出现问题
- javascript - jquery自动双击
- database - 数据工厂“段条件'@body ....'无效”
- reactjs - React 16 升级 - 选择列表返回 Object Object
- oauth-2.0 - Microsoft Power Automate 错误的 OAuth 令牌
- javascript - 根据数组元素的排序对 DOM 元素进行排序
- firebase - 如何翻译 Firebase 推送通知?