2014-12-04 46 views
0

我的PowerPoint幻燈片上有8個圖像庫。根據用戶表單輸入,通過在原始圖像名稱後面添加「1」或「2」以使它們可區分,某些組件得到複製和重命名。然後,我想分組新圖像(我正在構建組件圖像中的項目)。我能夠複製圖像並將它們排列正確,但我在分組時遇到問題。請注意,我並不總是將相同數量的項目分組,而是依賴於用戶輸入。Powerpoint VBA使複製形狀視圖處於活動狀態以選擇分組

我收到錯誤「Shape(unknown member):無效的請求。要選擇一個形狀,它的視圖必須是活動的。」

我搜索並試圖從幫助論壇實施幾個策略,但我是空的。

請幫助! -Kevin

的下面的代碼部分,因爲它是很長,但是這是我的第一個問題就出現了:

Dim Cargo As Shape, Cargo_Dup as Shape, Chemical as Shape, Chemical_Dup as Shape 
Set Cargo = ActivePresentation.Slides(2).Shapes("Cargo") 
Set Chemical = ActivePresentation.Slides(2).Shapes("Chemical") 
Cargo.Name = "Cargo" 
Chemical.Name = "Chemical" 

With ActivePresentation 
Set Cargo_Dup = ActivePresentation.Slides(2).Shapes("Cargo") 
    With Cargo_Dup.Duplicate 
     .Name = "Cargo_1st" 
     .Left = 0 
     .Top = 540 
    End With 
'CHEMICAL 
If Input1 = "Chemical" Then 
    Set Chemical_Dup = ActivePresentation.Slides(2).Shapes("Chemical") 
     With Chemical_Dup.Duplicate 
      .Name = "Chemical" & 1 
      .Left = 36.74352 
      .Top = 540 + 0.36 
     End With 
    '''''WHERE PROBLEM ARISES''''' 
    ActivePresentation.Slides(2).Shapes("Cargo_1st").Select 
    ActivePresentation.Slides(2).Shapes("Chemical1").Select msoFalse 
    Set Vehicle = ActiveWindow.Selection.ShapeRange.Group 
    Vehicle.Name = "Vehicle" 
'Elseif with a bunch for options where addition grouping occurs 
+0

顯示你的代碼。如果沒有這個,我們怎麼知道問題是什麼? – 2014-12-05 05:23:07

+0

添加到代碼中的代碼@TimWilliams – KevinJ25 2014-12-05 15:51:47

回答

0

我需要某種形式的鍵盤宏爲我輸入:

絕對不要選擇任何東西,除非你絕對必須。 你幾乎從不絕對必須。

您在問如何使視圖處於活動狀態,以便您可以選擇某些內容。 我認爲這是一個錯誤的問題。
知道如何使用形狀而不必選擇它們會更有用。 分組形狀沒有選擇它們有點棘手,但它可以完成。

這裏是你怎麼可能去這樣一個例子:

Sub GroupWithoutSelecting() 

    Dim oSl As Slide 
    Dim oSh As Shape 
    Dim aShapes() As String 

    Set oSl = ActivePresentation.Slides(2) ' or whichever slide you like 
    ReDim aShapes(1 To 1) 

    With oSl 
     For Each oSh In .Shapes 
      If oSh.Type <> msoPlaceholder Then ' can't group placeholders 

       ' Substitute the real condition you want to use 
       ' for selecting shapes to be grouped here 
       If oSh.Type = msoAutoShape Then 
        ' add it to the array 
        aShapes(UBound(aShapes)) = oSh.Name 
        ReDim Preserve aShapes(1 To UBound(aShapes) + 1) 
       End If 

      End If 
     Next 

     ' eliminate the last (empty) element in the array 
     ReDim Preserve aShapes(1 To UBound(aShapes) - 1) 

     ' Create a shaperange from the array members and group the shaperange 
     .Shapes.Range(aShapes).Group 

    End With ' oSl 

End Sub 
+0

我不理解你對''的評論替換你想用於選擇形狀的真實條件。「我不確定我將如何應用我需要做的事情這裏。 「Cargo_1st」將始終分組,但它可能是「Chemical1」或「Other1」,全部取決於用戶輸入的要複製的形狀。我希望能夠將「If Input1 =」Chemical「Then」和「ElseIF」塊中重複的新項目分組。 – KevinJ25 2014-12-05 22:17:27

+0

既然你沒有解釋分組後的邏輯,我不能提供正確的代碼,但是,例如,你可以建立一個字符串數組,每個元素包含一個要分組的形狀的名稱,那麼而不是如果oSh.Type = msoAutoShape將一個調用替換爲一個函數,該函數測試oSh.Name是否也是該數組的成員。 – 2014-12-06 17:54:19

+0

經過一些工作並添加了一些冗餘輸入檢查項後,我能夠使分組工作!它似乎有點圓,但它的工作原理和功能,所以我沒關係。我也能夠弄清楚如何命名我的新組。謝謝!! – KevinJ25 2014-12-06 19:18:58

相關問題