幻灯片 VBA "Out of Memory"
PowerPoint VBA "Out of Memory"
这是我第一次尝试在 PowerPoint 中使用 VBA,所以我希望这只是糟糕的代码设计,可以轻松修复。
每个月我都会制作一个演示文稿,该演示文稿基本上是一个 table 具有 3 列的值,代表过去 3 个月。当我下个月更新这个时,我希望中间的列成为左边的列,右边的列成为中间的列。然后右栏会得到新的数据。
目前我想做的只是 "move" 描述的跨列文本。像这样:
Sub MoveData()
Dim Infra1Array(270, 267, 211, 213, 50, 51, 145, 185) As Integer
For i = 1 To UBound(Infr1Array)
ActivePresentation.Slides(5).Shapes("" & Infr1Array(i) & "_1").TextFrame.TextRange.Text = ActivePresentation.Slides(5).Shapes("" & Infr1Array(i) & "_2").TextFrame.TextRange.Text
ActivePresentation.Slides(5).Shapes("" & Infr1Array(i) & "_2").TextFrame.TextRange.Text = ActivePresentation.Slides(5).Shapes("" & Infr1Array(i) & "_3").TextFrame.TextRange.Text
Next i
End Sub
如果你愿意,你可以在我的数组中看到 "rows"。然后每行有 3 个文本框,然后形状是带有 _1、_2 和 _3 的行号。
但是,当我 运行 这个循环时,我得到 "out of memory"。我是做错了什么还是对 PowerPoint 期望过高?
问题是您创建的多维数组:
Dim Infra1Array(270, 267, 211, 213, 50, 51, 145, 185) As Integer
这最终是 270 x 267 x 211 x 213 x 50 x 51 x 145 x 185 整数变量...这真的很多 :) > 200,000,000,000,000,000 以及您的系统内存可以处理的更多
我猜你想要一个包含这 8 个值的数组。在这种情况下:
Dim Infra1Array(7) As Integer
Infra1Array(0) = 270
Infra1Array(1) = 267
.
.
.
Infra1Array(7) = 185
当您仅将数组用于构建新字符串时,您还可以使用字符串数组和 Split() 函数。
总体:
Sub MoveData()
Dim Infra1Array() As String
Dim i As Integer
Infra1Array = Split("270, 267, 211, 213, 50, 51, 145, 185")
For i = LBound(Infra1Array) To UBound(Infra1Array)
ActivePresentation.Slides(5).Shapes("" & Infra1Array(i) & "_1").TextFrame.TextRange.Text = ActivePresentation.Slides(5).Shapes("" & Infra1Array(i) & "_2").TextFrame.TextRange.Text
ActivePresentation.Slides(5).Shapes("" & Infra1Array(i) & "_2").TextFrame.TextRange.Text = ActivePresentation.Slides(5).Shapes("" & Infra1Array(i) & "_3").TextFrame.TextRange.Text
Next i
End Sub
这是我第一次尝试在 PowerPoint 中使用 VBA,所以我希望这只是糟糕的代码设计,可以轻松修复。
每个月我都会制作一个演示文稿,该演示文稿基本上是一个 table 具有 3 列的值,代表过去 3 个月。当我下个月更新这个时,我希望中间的列成为左边的列,右边的列成为中间的列。然后右栏会得到新的数据。
目前我想做的只是 "move" 描述的跨列文本。像这样:
Sub MoveData()
Dim Infra1Array(270, 267, 211, 213, 50, 51, 145, 185) As Integer
For i = 1 To UBound(Infr1Array)
ActivePresentation.Slides(5).Shapes("" & Infr1Array(i) & "_1").TextFrame.TextRange.Text = ActivePresentation.Slides(5).Shapes("" & Infr1Array(i) & "_2").TextFrame.TextRange.Text
ActivePresentation.Slides(5).Shapes("" & Infr1Array(i) & "_2").TextFrame.TextRange.Text = ActivePresentation.Slides(5).Shapes("" & Infr1Array(i) & "_3").TextFrame.TextRange.Text
Next i
End Sub
如果你愿意,你可以在我的数组中看到 "rows"。然后每行有 3 个文本框,然后形状是带有 _1、_2 和 _3 的行号。
但是,当我 运行 这个循环时,我得到 "out of memory"。我是做错了什么还是对 PowerPoint 期望过高?
问题是您创建的多维数组:
Dim Infra1Array(270, 267, 211, 213, 50, 51, 145, 185) As Integer
这最终是 270 x 267 x 211 x 213 x 50 x 51 x 145 x 185 整数变量...这真的很多 :) > 200,000,000,000,000,000 以及您的系统内存可以处理的更多
我猜你想要一个包含这 8 个值的数组。在这种情况下:
Dim Infra1Array(7) As Integer
Infra1Array(0) = 270
Infra1Array(1) = 267
.
.
.
Infra1Array(7) = 185
当您仅将数组用于构建新字符串时,您还可以使用字符串数组和 Split() 函数。
总体:
Sub MoveData()
Dim Infra1Array() As String
Dim i As Integer
Infra1Array = Split("270, 267, 211, 213, 50, 51, 145, 185")
For i = LBound(Infra1Array) To UBound(Infra1Array)
ActivePresentation.Slides(5).Shapes("" & Infra1Array(i) & "_1").TextFrame.TextRange.Text = ActivePresentation.Slides(5).Shapes("" & Infra1Array(i) & "_2").TextFrame.TextRange.Text
ActivePresentation.Slides(5).Shapes("" & Infra1Array(i) & "_2").TextFrame.TextRange.Text = ActivePresentation.Slides(5).Shapes("" & Infra1Array(i) & "_3").TextFrame.TextRange.Text
Next i
End Sub