计数器在每张幻灯片后不重置形状编号

发布于 2025-01-11 06:20:48 字数 5537 浏览 0 评论 0原文

在下面的宏中,我无法将每张幻灯片的形状 IconDishChevronNavigator 重置为 1,以便稍后我可以选择它们以进一步编辑其属性。 我还尝试在创建形状后立即放置计数器,但看起来它在哪里并不重要,并且计数器不会停止。我也尝试将其停止在 iColumn 的值处,但什么也没有。

Option Explicit

Sub NavigatorX()

Dim oSlide As Slide

Dim oShapeNavigator As Shape
Dim IconDishNavigator As Shape
Dim ChevronNavigator As Shape

Dim nCounter As Long

Dim CellLeft As Single
Dim CellTop As Single
Dim CellWidth As Single
Dim CellHeight As Single
Dim CellWidth_2 As Single

Dim iRow As Integer
Dim iColumn As Integer

Dim Shp_Cntr As Single 'Center of Selected Shapes
Dim Shp_Mid As Single 

Dim NavWidth As Single
Dim EvenCell_W As Single

Dim DishCounter As Long
Dim ChevronCounter As Long

ChevronCounter = 0
DishCounter = 0

For Each oSlide In ActivePresentation.Slides

    If oSlide.CustomLayout.Name = "Section Header" Then
        nCounter = nCounter + 1

ElseIf nCounter > 0 Then

    Set oShapeNavigator = oSlide.Shapes.AddTable(1, 10, Left:=10, Top:=10, Width:=500, Height:=2)
                        oShapeNavigator.Fill.ForeColor.RGB = RGB(255, 128, 128)
                        oShapeNavigator.Name = "Navigator " & nCounter
                                
                              
            With oShapeNavigator.Table      '@@ TABLE @@
    
                For iRow = 1 To .Rows.Count
                For iColumn = 1 To .Columns.Count Step 2
                
                        EvenCell_W = (oShapeNavigator.Width / .Columns.Count / 2) * IIf(iColumn Mod 2 = 0, 5 / 7, 2 / 7)
                                
                        With .Columns(iColumn)
                        
                               .Width = EvenCell_W
                            
                               CellLeft = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Left
                               CellTop = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Top
                               CellWidth = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Width
                               CellHeight = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Height
                               Debug.Print CellWidth
                               Debug.Print CellHeight
            
                               Shp_Cntr = CellLeft + CellWidth / 2
                               Shp_Mid = CellTop + CellHeight / 2
                               
                                DishCounter = DishCounter + 1  
                                   ' <---- i put it here before, but it was still not counting right
                     
                            Set IconDishNavigator = oSlide.Shapes.AddShape(Type:=msoShapeOval, Left:=Shp_Cntr - CellHeight / 2, Top:=Shp_Mid - CellHeight / 2, Width:=CellHeight, Height:=CellHeight)
                     
                                   IconDishNavigator.Fill.ForeColor.RGB = RGB(100, 250, 140)
                                   IconDishNavigator.Line.Weight = 0.75
                                   IconDishNavigator.Line.Visible = msoFalse
                                   IconDishNavigator.LockAspectRatio = msoTrue
                                   IconDishNavigator.Name = "IconDish" & DishCounter
                                   
                        End With
                 Next iColumn
                 Next iRow
           End With
'

            With oShapeNavigator.Table      '@@ TABLE @@
                For iRow = 1 To .Rows.Count
                For iColumn = 2 To .Columns.Count Step 2
            
                                
                        With .Columns(iColumn)
                        
'                                   .Width = EvenCell_W
                                
                                   CellLeft = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Left
                                   CellTop = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Top
                                   CellWidth = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Width
                                   CellHeight = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Height
                                   Debug.Print CellWidth
                                   Debug.Print CellHeight
                
                                   Shp_Cntr = CellLeft + CellWidth / 2
                                   Shp_Mid = CellTop + CellHeight / 2
                                   ChevronCounter = ChevronCounter + 1
                                                        ' <---- i put it here before, but it was still not counting right
                                   
                     
                            Set ChevronNavigator = oSlide.Shapes.AddShape(Type:=msoShapeChevron, Left:=Shp_Cntr - CellHeight / 2, Top:=Shp_Mid - CellHeight / 2, Width:=CellWidth, Height:=CellHeight)
                                   ChevronNavigator.Fill.ForeColor.RGB = RGB(100, 100, 100)
                                   ChevronNavigator.Line.Weight = 0.75
                                   ChevronNavigator.Line.Visible = msoFalse
                                   ChevronNavigator.LockAspectRatio = msoTrue
                                   ChevronNavigator.Name = "Chevron" & ChevronCounter
                                   

                        End With
            
                Next iColumn
                Next iRow
            
            
            End With

End If
Next oSlide

         DishCounter = 0
         ChevronCounter = 0



End Sub


In the below macro, I cannot have the shapes IconDish and ChevronNavigator to reset to 1 for each slide, so that later I can select them for further editing of their properties.
I tried also to place the counter right after the shape is created, but it looks like it does not really matter where it is and the counter does not stop. I also tried to stop it at iColumn's value, but nothing.

Option Explicit

Sub NavigatorX()

Dim oSlide As Slide

Dim oShapeNavigator As Shape
Dim IconDishNavigator As Shape
Dim ChevronNavigator As Shape

Dim nCounter As Long

Dim CellLeft As Single
Dim CellTop As Single
Dim CellWidth As Single
Dim CellHeight As Single
Dim CellWidth_2 As Single

Dim iRow As Integer
Dim iColumn As Integer

Dim Shp_Cntr As Single 'Center of Selected Shapes
Dim Shp_Mid As Single 

Dim NavWidth As Single
Dim EvenCell_W As Single

Dim DishCounter As Long
Dim ChevronCounter As Long

ChevronCounter = 0
DishCounter = 0

For Each oSlide In ActivePresentation.Slides

    If oSlide.CustomLayout.Name = "Section Header" Then
        nCounter = nCounter + 1

ElseIf nCounter > 0 Then

    Set oShapeNavigator = oSlide.Shapes.AddTable(1, 10, Left:=10, Top:=10, Width:=500, Height:=2)
                        oShapeNavigator.Fill.ForeColor.RGB = RGB(255, 128, 128)
                        oShapeNavigator.Name = "Navigator " & nCounter
                                
                              
            With oShapeNavigator.Table      '@@ TABLE @@
    
                For iRow = 1 To .Rows.Count
                For iColumn = 1 To .Columns.Count Step 2
                
                        EvenCell_W = (oShapeNavigator.Width / .Columns.Count / 2) * IIf(iColumn Mod 2 = 0, 5 / 7, 2 / 7)
                                
                        With .Columns(iColumn)
                        
                               .Width = EvenCell_W
                            
                               CellLeft = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Left
                               CellTop = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Top
                               CellWidth = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Width
                               CellHeight = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Height
                               Debug.Print CellWidth
                               Debug.Print CellHeight
            
                               Shp_Cntr = CellLeft + CellWidth / 2
                               Shp_Mid = CellTop + CellHeight / 2
                               
                                DishCounter = DishCounter + 1  
                                   ' <---- i put it here before, but it was still not counting right
                     
                            Set IconDishNavigator = oSlide.Shapes.AddShape(Type:=msoShapeOval, Left:=Shp_Cntr - CellHeight / 2, Top:=Shp_Mid - CellHeight / 2, Width:=CellHeight, Height:=CellHeight)
                     
                                   IconDishNavigator.Fill.ForeColor.RGB = RGB(100, 250, 140)
                                   IconDishNavigator.Line.Weight = 0.75
                                   IconDishNavigator.Line.Visible = msoFalse
                                   IconDishNavigator.LockAspectRatio = msoTrue
                                   IconDishNavigator.Name = "IconDish" & DishCounter
                                   
                        End With
                 Next iColumn
                 Next iRow
           End With
'

            With oShapeNavigator.Table      '@@ TABLE @@
                For iRow = 1 To .Rows.Count
                For iColumn = 2 To .Columns.Count Step 2
            
                                
                        With .Columns(iColumn)
                        
'                                   .Width = EvenCell_W
                                
                                   CellLeft = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Left
                                   CellTop = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Top
                                   CellWidth = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Width
                                   CellHeight = oShapeNavigator.Table.Cell(iRow, iColumn).Shape.Height
                                   Debug.Print CellWidth
                                   Debug.Print CellHeight
                
                                   Shp_Cntr = CellLeft + CellWidth / 2
                                   Shp_Mid = CellTop + CellHeight / 2
                                   ChevronCounter = ChevronCounter + 1
                                                        ' <---- i put it here before, but it was still not counting right
                                   
                     
                            Set ChevronNavigator = oSlide.Shapes.AddShape(Type:=msoShapeChevron, Left:=Shp_Cntr - CellHeight / 2, Top:=Shp_Mid - CellHeight / 2, Width:=CellWidth, Height:=CellHeight)
                                   ChevronNavigator.Fill.ForeColor.RGB = RGB(100, 100, 100)
                                   ChevronNavigator.Line.Weight = 0.75
                                   ChevronNavigator.Line.Visible = msoFalse
                                   ChevronNavigator.LockAspectRatio = msoTrue
                                   ChevronNavigator.Name = "Chevron" & ChevronCounter
                                   

                        End With
            
                Next iColumn
                Next iRow
            
            
            End With

End If
Next oSlide

         DishCounter = 0
         ChevronCounter = 0



End Sub


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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文