我從一個文件夾插入一些圖片。該程序應該從文件夾的頂部開始,並按照降序插入圖片,但不會。從文件夾插入多個圖片降序
最初的3-5張圖片在演示文稿中最後顯示,而其他所有圖片都以完美的順序顯示。
Sub createTransModel()
Dim oSlide As Slide
Dim oPicture As Shape
Dim myFile As String
Dim myFolder As String
Dim pptLayout As CustomLayout
Dim fileName As String
Dim rotSlide As Slide
Set pptLayout = ActivePresentation.Slides(1).CustomLayout
myFolder = GetFolderPath()
myFile = Dir(myFolder & "*.png")
Do While myFile <> ""
Set oSlide = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, _
ppLayoutBlank)
Set oPicture = oSlide.Shapes.AddPicture(myFile, _
msoFalse, msoTrue, 1, 1, _
ActivePresentation.PageSetup.SlideWidth, _
ActivePresentation.PageSetup.SlideHeight)
myFile = Dir
Loop
fileName = inputBox("Please enter the filename")
ActivePresentation.SaveAs (fileName & ".pps")
End Sub
Public Function GetFolderPath() As String
Dim myFile As Object
Dim fileSelected As String
Dim path As String
Dim objPPT As Object
Dim i As Integer
Dim folderFromPath As String
Dim directory As String
directory = "M:\tm\public\Conti_Anlage\Voith Proben"
Set myFile = Application.FileDialog(msoFileDialogOpen)
With myFile
.InitialFileName = directory
.Title = "Choose File"
.AllowMultiSelect = False
If .Show <> -1 Then
Exit Function
End If
fileSelected = .SelectedItems(1)
End With
For i = Len(fileSelected) To 1 Step -1
If Mid(fileSelected, i, 1) = "\" Then
folderFromPath = Left(fileSelected, i)
Exit For
End If
Next
GetFolderPath = folderFromPath
End Function
如果您選擇的是第一個也是最後一個交換,那可能是因爲在文件對話框中使用的Windows資源管理器將它們交換了(由於過多的解決方法,它們無法再糾正的舊錯誤)。在這種情況下,交換列表中的第一個和最後一個項目。 – Christoph
我也有這個bug,但已經修復了。雖然它不在我發佈的代碼中。該錯誤似乎是獨立於那個 – Christian
不,我看,這不是你的問題在這裏,你手動循環瀏覽這些文件,而不是在文件對話框中選擇多個。 – Christoph