當我打電話每個模塊單獨一切正常......但是當我把他們從主要模塊中的文本不上保存的幻燈片溢出收縮。能否請你幫忙找到一種方法來解決這個的PowerPoint VBA創建和保存幻燈片
Sub MAIN()
Call Module1.CreateSlides
Call Module2.SaveSlides
End Sub
[模塊1]
Sub CreateSlides()
'Open the Excel workbook. Change the filename here.
Dim OWB As New Excel.Workbook
Set OWB = Excel.Application.Workbooks.Open("C:\B\Books\TXT.xlsx")
'Grab the first Worksheet in the Workbook
Dim WS As Excel.Worksheet
Set WS = OWB.Worksheets(1)
'Loop through each used row in Column A
For i = 1 To WS.Range("A65536").End(xlUp).Row
'Copy the first slide and paste at the end of the presentation
ActivePresentation.Slides(1).Copy
ActivePresentation.Slides.Paste (ActivePresentation.Slides.Count + 1)
'Change the text of the first text box on the slide.
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(1).TextFrame.TextRange.Text = WS.Cells(i, 1).Value
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(2).TextFrame.TextRange.Text = WS.Cells(i, 2).Value
ActivePresentation.Slides(ActivePresentation.Slides.Count).Shapes(3).TextFrame.TextRange.Text = WS.Cells(i, 3).Value
Next
'Close Excel
ActiveWorkbook.Close
'Delete presentation
ActivePresentation.Slides(1).Delete
End Sub
[單詞數]
Sub SaveSlides()
'Save slides as png
Dim sImagePath As String
Dim sImageName As String
Dim oSlide As Slide '* Slide Object
On Error GoTo Err_ImageSave
sImagePath = "C:\"
For Each oSlide In ActivePresentation.Slides
sImageName = oSlide.SlideNumber & ".png"
oSlide.Export sImagePath & sImageName, "PNG"
Next oSlide
Err_ImageSave:
If Err <> 0 Then
MsgBox Err.Description
End If
'Delete all slides
Dim Pre As Presentation
Set Pre = ActivePresentation
Dim x As Long
For x = Pre.Slides.Count To 1 Step -1
Pre.Slides(x).Delete
Next x
'Add New slide
Set pptLayout = ActivePresentation.Designs(1).SlideMaster.CustomLayouts(1)
Set Sld = ActivePresentation.Slides.AddSlide(1, pptLayout)
Sld.Design = ActivePresentation.Designs(1)
End Sub
您應該使用斷點上看到執行得好,如果不顯示你問題的原因(不太可能)你應該發佈調試結果。 – SantiBailors
你會發現你的錯誤? –
我嘗試過調試,但它沒有檢測到代碼本身的任何錯誤。如果我按下每個模塊的運行按鈕,則完全沒有問題。我有一長串模塊,我需要給他們打電話。你可以請檢查,以防我失去了一些東西。 excel文件有三列長文本,需要在溢出時收縮 – InDesigner