2017-02-27 6 views
1

私のプレゼンテーションを変換または固定しようとしています。ExcelからPowerPointスプレッドシートを作成する

下記のVBAコードを見つけましたwebsite下記の添付コードを少し変更しました。

残念ながら、私はスプレッドシートとプレゼンテーションに合っていません。

次に白い部分を見ることができます:

example

私の問題を解決する方法があれば驚いています。

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 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 = "B2:BH40" '<<<Change this range 

'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 = 1 
pp.ActiveWindow.Selection.ShapeRange.Left = 1 
pp.ActiveWindow.Selection.ShapeRange.Width = 720 

'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 

答えて

0

これは、スライドと同じサイズで貼り付けた形状のサイズを変更します:

Sub WorkbooktoPowerPoint() 
'Step 1: Declare your variables 
Dim pp As Object 
Dim PPPres As Object 
Dim PPSlide As Object 
Dim ppShape As Object 
Dim xlwksht As Worksheet 
Dim MyRange As String 
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 = "B2:BH40" '<<<Change this range 

'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) 

    'Step 7: Paste the picture and adjust its position 
    Set ppShape = PPSlide.Shapes.Paste 
    With ppShape 
     '.ShapeRange.Align msoAlignCenters, True 
     .Top = 0 
     .Left = 0 
     .Width = PPPres.PageSetup.SlideWidth 
     .Height = PPPres.PageSetup.SlideHeight 
    End With 'ppShape 
    '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 
+0

はどうもありがとうございました! また、私はpptの形を変えたいと思っていますが、それでもやはり動作せず、 "Invalid enumeration value"のエラーが出ます。 Googleにしようとしましたが、正解を見つけられませんでした。 ' 'ステップ2:オープンパワーポイント、新しいプレゼンテーションを追加し、可視 セットPP =のCreateObject( "PowerPoint.Application") 設定PPPres = pp.Presentations.Add PPPres.PageSetup.SlideSize = ppSlideSizeOnScreen 頁を作ります。 Visible = True' – Przemek

+0

ツアーに行くには少し時間がかかる:http://stackoverflow.com/tour。その変数が認識されないレイトバインディングを使用しているので、 'ppSlideSizeOnScreen'を1に置き換えてみてください。 – R3uK

+0

ありがとうございます!しかし、ステップ7でエラー438があります。この問題はコマンド '.Height = PPPres.PageSetup.SlideHeigth'にあります。 – Przemek

関連する問題