0

私はマクロ開発の初心者です。すべてのワークシートの特定の範囲 (B4:J40) を特定の位置の画像として別の ppt スライドにインポートするマクロがあります。これで問題ありません。達成したいのは、このマクロが同じスライドの同じワークシートから 2 つの範囲 (B4:D40 & E4:J40 など) を別の位置の画像としてインポートすることです。次に、このループは、現在のワークブックのすべてのワークシートに対して (現在と同様に) 続行する必要があります。

以下は私が現在使用しているコードです:

Sub WorkbooktoPowerPoint()

    'Step 1:  Declare your
    Dim pp As Object
    Dim PPPres As Object
    Dim PPSlide As Object
    Dim xlwksht As Worksheet
    Dim MyRange As String
`
    'Step 2:  Open PowerPoint, add a new presentation and make visible
    Set pp = CreateObject("PowerPoint.Application")
    Set PPPres = pp.Presentations.Add
    pp.Visible = True


    'Step 3:  Set the ranges for your data and
    MyRange = "B4:J25"

    'Step 4:  Start the loop through each worksheet
    For Each xlwksht In ActiveWorkbook.Worksheets
    xlwksht.Select
    Application.Wait (Now + TimeValue("0:00:1"))

    'Step 5:  Copy the range as picture
    xlwksht.Range(MyRange).CopyPicture _
    Appearance:=xlScreen, Format:=xlPicture

    'Step 6:  Count slides and add new blank slide as next available slide number
    '(the number 12 represents the enumeration for a Blank Slide)
    SlideCount = PPPres.Slides.Count
    Set PPSlide = PPPres.Slides.Add(SlideCount + 1, 12)
    PPSlide.Select

    'Step 7:  Paste the picture and adjust its position
    PPSlide.Shapes.Paste.Select
    pp.ActiveWindow.Selection.ShapeRange.Align msoAlignCenters, True
    pp.ActiveWindow.Selection.ShapeRange.Top = 65
    pp.ActiveWindow.Selection.ShapeRange.Left = 7.2
    pp.ActiveWindow.Selection.ShapeRange.Width = 700


    'Step 8:  Add the title to the slide then move to next worksheet
    Next xlwksht

    'Step 9:  Memory Cleanup
    pp.Activate
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set pp = Nothing
End Sub

コーディング言語の知識がないので、修正してください。前もって感謝します

4

1 に答える 1

0
    Sub WorkbooktoPowerPoint()

    'Step 1: Declare your variables
    Dim pp As Object
    Dim PPPres As Object
    Dim PPSlide As Object
    Dim xlwksht As Worksheet
    Dim MyRange As String
    Dim MyRange1 As String 'Define another Range
    Dim MyTitle As String

    'Step 2: Open PowerPoint, add a new presentation and make visible
    Set pp = CreateObject("PowerPoint.Application")
    Set PPPres = pp.Presentations.Add
    pp.Visible = True

    'Step 3: Set the ranges for your data and title
    MyRange = "B4:D7"
    MyRange1 = "E4:J7"
    'Step 4: Start the loop through each worksheet
    For Each xlwksht In ActiveWorkbook.Worksheets
    xlwksht.Select Application.Wait(Now + TimeValue("0:00:1"))
    'Step 5: Copy the range as picture
    xlwksht.Range(MyRange).CopyPicture Appearance:=xlScreen, Format:=xlPicture
    'Step 6: Count slides and add new blank slide as next available slide number '(the number 12 represents the enumeration for a Blank Slide)
    SlideCount = PPPres.Slides.Count
    Set PPSlide = PPPres.Slides.Add(SlideCount + 1, 12)
    PPSlide.Select
    'Step 7: Paste the picture and adjust its position
    PPSlide.Shapes.Paste.Select
    pp.ActiveWindow.Selection.ShapeRange.Align msoAlignTops, True
    pp.ActiveWindow.Selection.ShapeRange.Top = 65
    pp.ActiveWindow.Selection.ShapeRange.Left = 7.2
    pp.ActiveWindow.Selection.ShapeRange.Width = 700
    'Step 8: Add the title to the slide then move to next worksheet
    xlwksht.Range(MyRange1).CopyPicture Appearance:=xlScreen, Format:=xlPicture
    PPSlide.Shapes.Paste.Select
    pp.ActiveWindow.Selection.ShapeRange.Align msoAlignBottoms, True
    'You can set the second image prostion here
    pp.ActiveWindow.Selection.ShapeRange.Top = 765
    pp.ActiveWindow.Selection.ShapeRange.Left = 7.2
    pp.ActiveWindow.Selection.ShapeRange.Width = 700

    Next xlwksht

    'Step 9: Memory Cleanup 
    pp.Activate
    Set PPSlide = Nothing
    Set PPPres = Nothing
    Set pp = Nothing

    End Sub
于 2013-02-18T07:36:36.673 に答える