PC Review


Reply
Thread Tools Rate Thread

Automation from Access

 
 
=?Utf-8?B?QWRhbSBNaWxsaWdhbg==?=
Guest
Posts: n/a
 
      14th Jun 2006
All-

I am designing an application in Access 2003. What I woul dlike to do
through VBA is open a new, blank powerpoint presentation, add slides to the
presentation from four or five saved presentations and save the new
prentation. I already have the code that will loop through the filepaths of
the presentations I want to add, and I think I have opend up a new
presentation. Here is the code I have

Dim ppt As PowerPoint.Application
Dim pres As PowerPoint.Presentation

Set ppt = CreateObject("PowerPoint.Application")
Set pres = ppt.Presentations.Add

Do While recPowerPoint.EOF = False 'recPowerPoint is a recordset with the
file names I want to add

sFile = sFilePath & recPowerPoint("strTitle") & ".ppt" 'sFilePath is a user
defined variable for wherever they want to save the ppt files

ActivePresentation.Slides.InsertFromFile sFile, 1 'This is where I am
getting the error

recPowerPoint.MoveNext

Loop

ActivePresentation.SaveAs "c:/New.ppt"

Like I said, I get an error "ActiveX component can't create object" On the
ActivePresntation.Slides.InsertFromFile part of the code. I am new to
PowerPoint VBA nad any help would be appreciated. Thanks

Adam

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWRhbSBNaWxsaWdhbg==?=
Guest
Posts: n/a
 
      15th Jun 2006

All-

I did some more digging and solved my own problem. For those interested,
here is my hack solution:

Public Sub PowerPnt()

Dim recPowerPoint As Recordset
Dim sFilePath As String
Dim numService As Integer
Dim sql As String
Dim sFile As String
Dim ppt As PowerPoint.Application
Dim pres As PowerPoint.Presentation

numService = Forms!frmWorshipServiceInfo.anuServiceID 'get the servie ID
from the user form
sFilePath = Forms!frmHome.strPowerPointFilepath 'get the Power Point
filepath from the userform

Set ppt = CreateObject("PowerPoint.Application") 'create an instance of
Powerpoint
Set pres = ppt.Presentations.Add 'create a new presentation

sql = "SELECT * FROM qryPowerPoint WHERE numService = " & numService & "
ORDER BY numOrder DESC" 'create SQL that will get only the songs

'from the desired service, sorted DESC since

' slides are added at the beginning
Set recPowerPoint = CurrentDb.OpenRecordset(sql) 'open recordset from SQL
above

Do While recPowerPoint.EOF = False
sFile = sFilePath & recPowerPoint("strTitle") & ".ppt" 'create the entire
filepath including the Title of the song

If Not Dir$(sFile) <> "" Then 'if the file does not exist, tell the user and
move to the next record
MsgBox "The file " & sFile & " could not be found and was not added."
recPowerPoint.MoveNext

Else

With pres 'if the file does exist, insert all of the slides from that
presentation into the new one
..Slides.InsertFromFile sFile, 0
End With

recPowerPoint.MoveNext

End If

Loop

With pres
.SaveAs sFilePath & "New.ppt" 'save the file in the same directory as the
songs
End With

End Sub

If you see any problems with this code please let me know. The one problem
I am having is that it does not import the backgrounds as well. Does anyone
know how I would do that?

Adam Milligan


"Adam Milligan" wrote:

> All-
>
> I am designing an application in Access 2003. What I woul dlike to do
> through VBA is open a new, blank powerpoint presentation, add slides to the
> presentation from four or five saved presentations and save the new
> prentation. I already have the code that will loop through the filepaths of
> the presentations I want to add, and I think I have opend up a new
> presentation. Here is the code I have
>
> Dim ppt As PowerPoint.Application
> Dim pres As PowerPoint.Presentation
>
> Set ppt = CreateObject("PowerPoint.Application")
> Set pres = ppt.Presentations.Add
>
> Do While recPowerPoint.EOF = False 'recPowerPoint is a recordset with the
> file names I want to add
>
> sFile = sFilePath & recPowerPoint("strTitle") & ".ppt" 'sFilePath is a user
> defined variable for wherever they want to save the ppt files
>
> ActivePresentation.Slides.InsertFromFile sFile, 1 'This is where I am
> getting the error
>
> recPowerPoint.MoveNext
>
> Loop
>
> ActivePresentation.SaveAs "c:/New.ppt"
>
> Like I said, I get an error "ActiveX component can't create object" On the
> ActivePresntation.Slides.InsertFromFile part of the code. I am new to
> PowerPoint VBA nad any help would be appreciated. Thanks
>
> Adam
>

 
Reply With Quote
 
Steve Rindsberg
Guest
Posts: n/a
 
      15th Jun 2006
In article <EF2FF7C4-680C-4821-B8AC-(E-Mail Removed)>, Adam Milligan
wrote:
> All-
>
> I am designing an application in Access 2003. What I woul dlike to do
> through VBA is open a new, blank powerpoint presentation, add slides to the
> presentation from four or five saved presentations and save the new
> prentation. I already have the code that will loop through the filepaths of
> the presentations I want to add, and I think I have opend up a new
> presentation. Here is the code I have
>
> Dim ppt As PowerPoint.Application
> Dim pres As PowerPoint.Presentation
>
> Set ppt = CreateObject("PowerPoint.Application")
> Set pres = ppt.Presentations.Add
>
> Do While recPowerPoint.EOF = False 'recPowerPoint is a recordset with the
> file names I want to add
>
> sFile = sFilePath & recPowerPoint("strTitle") & ".ppt" 'sFilePath is a user
> defined variable for wherever they want to save the ppt files
>
> ActivePresentation.Slides.InsertFromFile sFile, 1 'This is where I am
> getting the error


There's no ActivePresentation object in Access, hence the error.
Try this instead:

Pres.Slides.InsertFromFile sFile, 1

>
> recPowerPoint.MoveNext
>
> Loop
>
> ActivePresentation.SaveAs "c:/New.ppt"


And instead of that,

Pres.SaveAs etc ...

>
> Like I said, I get an error "ActiveX component can't create object" On the
> ActivePresntation.Slides.InsertFromFile part of the code. I am new to
> PowerPoint VBA nad any help would be appreciated. Thanks
>
> Adam
>


-----------------------------------------
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Access automation leaves Excel open which in turn locks 2nd automation attempts EagleOne@discussions.microsoft.com Microsoft Access 8 30th Jun 2008 01:27 AM
More automation in Access =?Utf-8?B?RnJlZWhhbDA0?= Microsoft Access Getting Started 4 15th Nov 2006 02:47 AM
Automation - running code in one Access DB from another Access DB Phred Bear Microsoft Access VBA Modules 7 26th Jan 2005 04:10 AM
Automation w/ Access TD Microsoft Access VBA Modules 1 6th Apr 2004 06:18 AM
Access Automation in ASP.NET / C# =?Utf-8?B?U2NvdHQ=?= Microsoft ASP .NET 0 29th Feb 2004 11:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:42 PM.