[Debutante] Utilisation de VB pour creer des diapos Powerpoint.
Le
Cendrine
Bonjour à tous et à toutes
Je cherche à générer une présentation Powerpoint via une interface VB.
J'ai trouvé sur le net un exemple de code, et je l'ai utilisé. Cela à
fonctionné pendant un temps, mais actuellement j'ai un massage d'erreur:
"Argument not optional" au niveau de :
On Error GoTo OLEConnect_Err
Set obj = CreateObject(,sClass)
Je ne suis que débutante dans l'utilisation du VB et je ne sais absolument
pas comment faire pour solutionner mon problème.
Auriez vous une idée.
Je vous en remercie d'avance.
Bonne Journée
'
Public PowerPoint As PowerPoint.Application
'Public ComNewComment As PowerPoint.NotesPage
Public sldNewSlide As PowerPoint.Slide
Public shpCurrShape As PowerPoint.Shape
Public mblnPowerPointStarted As Boolean
Public pptPres As Presentation ' Presentation Object (your PPT file).
Public pptSlide As Slide ' Slide Object (the current slide).
Public Sub Gestion_PowerPoint()
'
' Creates and runs the presentation.
'
Dim lngSlideHeight As Long
Dim lngSlideWidth As Long
'--
' Establish a connection with PowerPoint.
'--
mblnPowerPointStarted = OLEConnect(PowerPoint, "PowerPoint.Application")
PowerPoint.Visible = True
'--
' Add a new (blank) presentation to PowerPoint.
'--
Set pptPres = PowerPoint.Presentations.Add
With pptPres
.ApplyTemplate FileName:="C:\DATA\VBtest\BioABase.pot"
End With
' With ActivePresentation
' Determine height and width of slide.
With pptPres.PageSetup
lngSlideHeight = .SlideHeight
lngSlideWidth = .SlideWidth
End With
'--
' Add new slide to end of presentation.
'--
Set sldNewSlide = pptPres.Slides.Add(1, ppLayoutBlank)
With sldNewSlide
Set shpCurrShape = .Shapes.AddShape(msoShapeRoundedRectangle, 100#, 150#,
520#, 300#)
Call RectangleRond(shpCurrShape, RGB(51, 51, 255))
Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 150,
160, 400, 150)
texto = DGroupProjName & vbCrLf & GeneFullName & vbCrLf
Call ajoutText(shpCurrShape, RGB(51, 51, 255), texto, 28)
Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 150,
235, 400, 150)
Call ajoutText(shpCurrShape, RGB(51, 51, 255), ProjAliases, 18)
Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 150,
400, 400, 150)
texto = DateMonth & ", " & DataYear
Call ajoutTextnonOmbre(shpCurrShape, RGB(51, 51, 255), texto, 24)
End With
'
' Terminates PowerPoint if this application started it.
'
Private Sub Form_Unload(Cancel As Integer)
If mblnPowerPointStarted Then PowerPoint.Quit
End Sub
Private Function OLEConnect(obj As Object, sClass As String) As Boolean
'
' Temporarily turn off error handling.
'--
On Error Resume Next
Set obj = GetObject(, sClass)
'--
' If GetObject failed, then try Create.
'--
If Err = 429 Then
'-
' Resume Error Handling.
'-
On Error GoTo OLEConnect_Err
Set obj = CreateObject(,sClass)
'-
' If this line was executed, then the app was started.
'-
OLEConnect = True
'--
' If any other error occurs, then display it and exit.
'--
ElseIf Err <> 0 Then
GoSub OLEConnect_Err
End If
Exit Function
'
' Display error message and abort.
'
OLEConnect_Err:
MsgBox Err.Description, vbCritical
' Unload Me
Exit Function
End Function
Je cherche à générer une présentation Powerpoint via une interface VB.
J'ai trouvé sur le net un exemple de code, et je l'ai utilisé. Cela à
fonctionné pendant un temps, mais actuellement j'ai un massage d'erreur:
"Argument not optional" au niveau de :
On Error GoTo OLEConnect_Err
Set obj = CreateObject(,sClass)
Je ne suis que débutante dans l'utilisation du VB et je ne sais absolument
pas comment faire pour solutionner mon problème.
Auriez vous une idée.
Je vous en remercie d'avance.
Bonne Journée
'
Public PowerPoint As PowerPoint.Application
'Public ComNewComment As PowerPoint.NotesPage
Public sldNewSlide As PowerPoint.Slide
Public shpCurrShape As PowerPoint.Shape
Public mblnPowerPointStarted As Boolean
Public pptPres As Presentation ' Presentation Object (your PPT file).
Public pptSlide As Slide ' Slide Object (the current slide).
Public Sub Gestion_PowerPoint()
'
' Creates and runs the presentation.
'
Dim lngSlideHeight As Long
Dim lngSlideWidth As Long
'--
' Establish a connection with PowerPoint.
'--
mblnPowerPointStarted = OLEConnect(PowerPoint, "PowerPoint.Application")
PowerPoint.Visible = True
'--
' Add a new (blank) presentation to PowerPoint.
'--
Set pptPres = PowerPoint.Presentations.Add
With pptPres
.ApplyTemplate FileName:="C:\DATA\VBtest\BioABase.pot"
End With
' With ActivePresentation
' Determine height and width of slide.
With pptPres.PageSetup
lngSlideHeight = .SlideHeight
lngSlideWidth = .SlideWidth
End With
'--
' Add new slide to end of presentation.
'--
Set sldNewSlide = pptPres.Slides.Add(1, ppLayoutBlank)
With sldNewSlide
Set shpCurrShape = .Shapes.AddShape(msoShapeRoundedRectangle, 100#, 150#,
520#, 300#)
Call RectangleRond(shpCurrShape, RGB(51, 51, 255))
Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 150,
160, 400, 150)
texto = DGroupProjName & vbCrLf & GeneFullName & vbCrLf
Call ajoutText(shpCurrShape, RGB(51, 51, 255), texto, 28)
Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 150,
235, 400, 150)
Call ajoutText(shpCurrShape, RGB(51, 51, 255), ProjAliases, 18)
Set shpCurrShape = .Shapes.AddTextbox(msoTextOrientationHorizontal, 150,
400, 400, 150)
texto = DateMonth & ", " & DataYear
Call ajoutTextnonOmbre(shpCurrShape, RGB(51, 51, 255), texto, 24)
End With
'
' Terminates PowerPoint if this application started it.
'
Private Sub Form_Unload(Cancel As Integer)
If mblnPowerPointStarted Then PowerPoint.Quit
End Sub
Private Function OLEConnect(obj As Object, sClass As String) As Boolean
'
' Temporarily turn off error handling.
'--
On Error Resume Next
Set obj = GetObject(, sClass)
'--
' If GetObject failed, then try Create.
'--
If Err = 429 Then
'-
' Resume Error Handling.
'-
On Error GoTo OLEConnect_Err
Set obj = CreateObject(,sClass)
'-
' If this line was executed, then the app was started.
'-
OLEConnect = True
'--
' If any other error occurs, then display it and exit.
'--
ElseIf Err <> 0 Then
GoSub OLEConnect_Err
End If
Exit Function
'
' Display error message and abort.
'
OLEConnect_Err:
MsgBox Err.Description, vbCritical
' Unload Me
Exit Function
End Function

Poser une question


AMHA, la virgule a été introduite par erreur devant sClass.
Essaye de supprimer la virugle de cette ligne...
--
François Picalausa (MVP VB)
FAQ VB : http://faq.vb.free.fr
MSDN : http://msdn.microsoft.com
"Cendrine" news:
"François Picalausa" news:eG$