如何在目录

时间:2015-06-11 03:08:39

标签: vba powerpoint-vba

我已经修改了ImportABunch代码,几乎可以完成我需要的一切,我需要在幻灯片1上导入2个图像(目录中的第一个文件,然后是唯一命名的文件,对于幻灯片2我有第二个图像文件)目录,对于幻灯片3,我不知道如何让代码从文件3开始然后工作到最后,它抓住幻灯片3的第一个图像,然后是幻灯片4的第三个图像。

任何帮助将不胜感激, -Glenn

Option Explicit

Sub ImportFigs()

Dim strTemp As String
Dim strPath As String
Dim strFileSpec As String
Dim oSld As Slide
Dim oPic As Shape

' Table1:
strPath = "C:\Users\Glider\Desktop\RW\Mary_Celeste_Images\"
strFileSpec = "01*.png"

strTemp = Dir(strPath & strFileSpec)

Do While strTemp <> ""
    Set oSld = ActivePresentation.Slides(1)
    Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
    LinkToFile:=msoFalse, _
    SaveWithDocument:=msoTrue, _
    Left:=432, _
    Top:=123.12, _
    Width:=341.28, _
    Height:=390.96)




    strTemp = Dir
Loop

' MapperImage:
strPath = "C:\Users\Glider\Desktop\RW\Mary_Celeste_Images\"
strFileSpec = "mapper.jpg"

strTemp = Dir(strPath & strFileSpec)

Do While strTemp <> ""
    Set oSld = ActivePresentation.Slides(1)
    Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
    LinkToFile:=msoFalse, _
    SaveWithDocument:=msoTrue, _
    Left:=42.47, _
    Top:=311.76, _
    Width:=353.21, _
    Height:=236.16)

    strTemp = Dir
Loop

' Table2:
strPath = "C:\Users\Glider\Desktop\RW\Mary_Celeste_Images\"
strFileSpec = "02*.jpg"

strTemp = Dir(strPath & strFileSpec)

Do While strTemp <> ""
    Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
    Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
    LinkToFile:=msoFalse, _
    SaveWithDocument:=msoTrue, _
    Left:=0, _
    Top:=75, _
    Width:=-1, _
    Height:=-1)

    strTemp = Dir
Loop

' Body:
strPath = "C:\Users\Glider\Desktop\RW\Mary_Celeste_Images\"
strFileSpec = "*.png"

strTemp = Dir(strPath & strFileSpec)

Do While strTemp <> ""
    Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
    Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
    LinkToFile:=msoFalse, _
    SaveWithDocument:=msoTrue, _
    Left:=30, _
    Top:=80, _
    Width:=756, _
    Height:=450.44)

    strTemp = Dir
Loop

' LastPage:
strPath = "C:\Users\Glider\Desktop\RW\Mary_Celeste_Images\"
strFileSpec = "lastpage.jpg"

strTemp = Dir(strPath & strFileSpec)

Do While strTemp <> ""
    Set oSld = ActivePresentation.Slides.Add(ActivePresentation.Slides.Count + 1, ppLayoutBlank)
    Set oPic = oSld.Shapes.AddPicture(FileName:=strPath & strTemp, _
    LinkToFile:=msoFalse, _
    SaveWithDocument:=msoTrue, _
    Left:=0, _
    Top:=72, _
    Width:=792, _
    Height:=487.44)

    strTemp = Dir
Loop

End Sub

0 个答案:

没有答案