Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Powerpoint VBA in QM
#1
Hello All,
I found a very useful piece of VBA code that I am able to run in PPT (Alt-F8, choose VBA sub name) which imports a bunch of pictures from a folder, 1 image per slide, full screen:


Quote:Sub ImportFullScreen()

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

' Edit these to suit:
strPath = "C:\Image Import Folder\"
strFileSpec = "*.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:=0, _
Width:=0, _
Height:=0)

' Reset it to its "real" size
With oPic
.ScaleHeight 1, msoTrue
.ScaleWidth 1, msoTrue
End With

With oPic
Dim appssw, appssh
appssw = ActivePresentation.PageSetup.SlideWidth
appssh = ActivePresentation.PageSetup.SlideHeight
.LockAspectRatio = msoTrue
If oPic.Width / oPic.Height > appssw / appssh Then
.Width = appssw
.Top = (appssh - oPic.Height) / 2
Else
.Height = appssh
.Left = (appssw - oPic.Width) / 2
End If
End With

strTemp = Dir
Loop

End Sub


This works fine but is not that useful for automation because I have to make sure macros enabled, click Alt-F8, choose sub name, etc.
I would much rather drive ppt from QM.
Is the above even possible to do through VBA in QM? I have tried a little VBA in outlook from QM but can't seem to see how to convert the VBA:

I got this far:

Macro Macro12
Code:
Copy      Help
typelib PowerPoint {91493440-5A91-11CF-8700-00AA0060263B} 2.8

PowerPoint.Application ap._getactive;
int SlideCount = ap.ActivePresentation.Slides.Count
out SlideCount
int oSld = ap.ActivePresentation.slides.Add(SlideCount, ppLayoutBlank)
PowerPoint.Presentation pres
str strPath  =   "C:\Image Import Folder\"

PowerPoint.Slide Slide.Shapes.AddPicture(PicPath  )


but then could not figure out how to format the slide add picture like this as in the VBA script:
Error in Macro12: Expected 7 arguments, not 1.
Shape AddPicture(BSTR'FileName LinkToFile SaveWithDocument FLOAT'Left FLOAT'Top [FLOAT'Width=-1] [FLOAT'Height=-1]) ;;LinkToFile: msoTrue msoFalse msoCTrue msoTriStateToggle msoTriStateMixed ;;SaveWithDocument: msoTrue msoFalse msoCTrue msoTriStateToggle msoTriStateMixed
etc....

Any formatting hints?
Thanks,
S
#2
Macro Macro2253
Code:
Copy      Help
typelib Office {2DF8D04C-5BFA-101B-BDE5-00AA0044DE52} 2.2 ;;the mso constants are here
typelib PowerPoint {91493440-5A91-11CF-8700-00AA0060263B} 2.8

str strPath.expandpath("$my qm$\")
PowerPoint.Application app._getactive
PowerPoint.Presentation p=app.ActivePresentation
int SlideCount = p.Slides.Count
out SlideCount
str strTemp="copy.jpg"
PowerPoint.Slide oSld = p.slides.Add(SlideCount, ppLayoutBlank)
PowerPoint.Shape oPic=oSld.Shapes.AddPicture(F"{strPath}{strTemp}" msoFalse msoTrue 0 0 0 0)
#3
This helps immensely! Thank you. I got a little farther myself since my last post. I finally got the hang of defining a variabe as PowerPoint.[SOMETHING] var wherever the vba would just say "set".
Sometimes it is hard to figure out exactly what the [SOMETHING] is to choose but QM provides the . choices so intuition and trial and error, and MSDN, will eventually get me there (with a "little" help from you of course!!!!).

Thanks so much, I can handle all the Do Loops and the rest on my own with QM file/folder functions and QM syntax.
Thanks and Happy Easter!!!
S


Forum Jump:


Users browsing this thread: 2 Guest(s)