williecg
asked on
Using Slide object in msaccess
msaccess, powerpoint, vba
I am using vba in msaccess to change link references in powerpoint. The script I found has
Dim oSld As Slide
Dim oSh As Shape
I am getting an error 429, ActiveX Component can't create object.
I think I do not have the proper object library loaded in msaccess 2016.
Any suggestions.
Thanks,
WillieCg
I am using vba in msaccess to change link references in powerpoint. The script I found has
Dim oSld As Slide
Dim oSh As Shape
I am getting an error 429, ActiveX Component can't create object.
I think I do not have the proper object library loaded in msaccess 2016.
Any suggestions.
Thanks,
WillieCg
Have you selected the Microsoft PowerPoint N.N Object Library in the References library?
You can add the PowerPoint X.Y Object Library as Paul suggests and use Early Binding for your non-Access objects. And I would only do this for the development phase because if you intend to distribute the solutions, it may not end up on a PC with the same version of the library and hence will raise a compiler error. It's better to use late bound objects like this:
Even better is to do something like this which allows you to use IntelliSense with the library's OM during dev and then remove the reference and set the DEV_MODE to false for production:
You'll need to do the same for any PowerPoint-specific constants and enumerations.
Dim oSld As Object ' Slide
Dim oSh As Object ' Shape
Even better is to do something like this which allows you to use IntelliSense with the library's OM during dev and then remove the reference and set the DEV_MODE to false for production:
' During Dev : To use IntelliSense, set to true and add a reference to the Microsoft PowerPoint X.Y Object Library
' Production : Set to false and move the reference.
#Const DEV_MODE = True
#If DEV_MODE Then
Dim oSld As Slide
Dim oSh As Shape
#Else
Dim oSld As Object
Dim oSh As Object
#End If
You'll need to do the same for any PowerPoint-specific constants and enumerations.
ASKER
No, I have not. Also I did not see Microsoft PowerPoint N.N Object Library as one of the items in my access 2016 object library.
Suggestions, I am a newbe
thanks
Suggestions, I am a newbe
thanks
ASKER
I do not see the PowerPoint X.Y Object Library ?
Perhaps there if a reference file I do not have loaded.
thanks,
Perhaps there if a reference file I do not have loaded.
thanks,
ASKER
Thanks,
It loaded with my original install
Microsoft PowerPoint 16.0 Object Library
There is not a reference to Microsoft PowerPoint X.Y Object Library
WillieCg
It loaded with my original install
Microsoft PowerPoint 16.0 Object Library
There is not a reference to Microsoft PowerPoint X.Y Object Library
WillieCg
ASKER
It is checked.
powerpoint 16.0 object library
powerpoint 16.0 object library
Huh. Check the folder (location is defined in the lower part of the window) and confirm that the file is there. If not, search your "C" drive for the file; if it is, I'm completely stumped.
In order to get a reference to those two objects you need references to their parent objects as in this hierarchy:
PowerPoint Application -> Presentation -> Slide -> Shape
So did you already create references to the application and presentation objects?
PowerPoint Application -> Presentation -> Slide -> Shape
So did you already create references to the application and presentation objects?
I think it would be most helpful to share a bigger chunk of your code...maybe the error lies some where else...have you created the PowerPoint object ?
e.g.
e.g.
Dim pwrPoint as Object
Set pwrPoint = CreateObject("Powerpoint.Application")
ASKER
the following works in vb in powerpoint, in access i get "Error 429, ActiveX component can't create object"
here is code
Private Sub cmd_update_OLE_Links_Click ()
Dim oSld As Slide
Dim oSh As Shape
Dim sOldPath As String
Dim sNewPath As String
' EDIT THIS TO REFLECT THE PATHS YOU WANT TO CHANGE
' Include just the portion of the path you want to change
' For example, to change links to reflect that files have moved from
' \\boss\p-drive\temp\*.* to
' \\boss\Q-drive\temp\*.*
sOldPath = "\act_34-Bossier"
sNewPath = "\act_34-North_Bossier"
On Error GoTo ErrorHandler
For Each oSld In ActivePresentation.Slides
For Each oSh In oSld.Shapes
' Change only linked OLE objects
If oSh.Type = msoLinkedOLEObject Then
On Error Resume Next
' Verify that file exists
If Len(Dir$(Replace(oSh.LinkF ormat.Sour ceFullName , sOldPath, sNewPath))) > 0 Then
oSh.LinkFormat.SourceFullN ame = Replace(oSh.LinkFormat.Sou rceFullNam e, sOldPath, sNewPath)
Else
MsgBox ("File is missing; cannot relink to a file that isn't present")
End If
On Error GoTo ErrorHandler
End If
Next ' shape
Next ' slide
MsgBox ("Done!")
NormalExit:
Exit Sub
ErrorHandler:
MsgBox ("Error " & Err.Number & vbCrLf & Err.Description)
Resume NormalExit
End Sub
here is code
Private Sub cmd_update_OLE_Links_Click
Dim oSld As Slide
Dim oSh As Shape
Dim sOldPath As String
Dim sNewPath As String
' EDIT THIS TO REFLECT THE PATHS YOU WANT TO CHANGE
' Include just the portion of the path you want to change
' For example, to change links to reflect that files have moved from
' \\boss\p-drive\temp\*.* to
' \\boss\Q-drive\temp\*.*
sOldPath = "\act_34-Bossier"
sNewPath = "\act_34-North_Bossier"
On Error GoTo ErrorHandler
For Each oSld In ActivePresentation.Slides
For Each oSh In oSld.Shapes
' Change only linked OLE objects
If oSh.Type = msoLinkedOLEObject Then
On Error Resume Next
' Verify that file exists
If Len(Dir$(Replace(oSh.LinkF
oSh.LinkFormat.SourceFullN
Else
MsgBox ("File is missing; cannot relink to a file that isn't present")
End If
On Error GoTo ErrorHandler
End If
Next ' shape
Next ' slide
MsgBox ("Done!")
NormalExit:
Exit Sub
ErrorHandler:
MsgBox ("Error " & Err.Number & vbCrLf & Err.Description)
Resume NormalExit
End Sub
Could you pop that code snippet into a code block so we can easily reference the lines? This line will work in PowerPoint because it will be running from the active presentation but in Access, you need to set a reference to the active presentation first:
Do you plan to have access open the file from the file system or will it already be open or will it need to be created?
For Each oSld In ActivePresentation.Slides
Do you plan to have access open the file from the file system or will it already be open or will it need to be created?
You need to add this at the top:
Then you need to set a reference to the PowerPoint app using either GetObject (PowerPoint is already open) or CreateObject (PowerPoint isn't open):
Then you need to open the required presentation file and set a reference to that:
Then you access the slide objects as in your original code, now modified to include the above:
Dim oPP as PowerPoint.Application
Dim oPres as Presentation
Then you need to set a reference to the PowerPoint app using either GetObject (PowerPoint is already open) or CreateObject (PowerPoint isn't open):
Set oPP = CreateObject("PowerPoint.Application")
Then you need to open the required presentation file and set a reference to that:
Set oPres = oPP.Presentations.Open("C:\myPresentation.pptx") ' Use a file dialog to get this or is it a fixed folder and file?
Then you access the slide objects as in your original code, now modified to include the above:
Private Sub cmd_update_OLE_Links_Click()
Dim oPP as PowerPoint.Application
Dim oPres as Presentation
Dim oSld As Slide
Dim oSh As Shape
Dim sOldPath As String
Dim sNewPath As String
' EDIT THIS TO REFLECT THE PATHS YOU WANT TO CHANGE
' Include just the portion of the path you want to change
' For example, to change links to reflect that files have moved from
' \\boss\p-drive\temp\*.* to
' \\boss\Q-drive\temp\*.*
sOldPath = "\act_34-Bossier"
sNewPath = "\act_34-North_Bossier"
On Error GoTo ErrorHandler
' Start PowerPoint
Set oPP = CreateObject("PowerPoint.Application")
' Open a presentation
Set oPres = oPP.Presentations.Open("C:\myPresentation.pptx")
For Each oSld In oPres.Slides
For Each oSh In oSld.Shapes
' Change only linked OLE objects
If oSh.Type = msoLinkedOLEObject Then
On Error Resume Next
' Verify that file exists
If Len(Dir$(Replace(oSh.LinkFormat.SourceFullName, sOldPath, sNewPath))) > 0 Then
oSh.LinkFormat.SourceFullName = Replace(oSh.LinkFormat.SourceFullName, sOldPath, sNewPath)
Else
MsgBox ("File is missing; cannot relink to a file that isn't present")
End If
On Error GoTo ErrorHandler
End If
Next ' shape
Next ' slide
MsgBox ("Done!")
NormalExit:
Exit Sub
ErrorHandler:
MsgBox ("Error " & Err.Number & vbCrLf & Err.Description)
Resume NormalExit
End Sub
ASKER
I pasted the code into 2016 access vb editor and changed this line
Set oPres = oPP.Open("y:\test.pptx")
When I ran it I got the following error
compile error: Method or data member not found
Thanks,
WillieCg
Set oPres = oPP.Open("y:\test.pptx")
When I ran it I got the following error
compile error: Method or data member not found
Thanks,
WillieCg
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
thanks, I am out of town for several days, when I return I will give it a try. thanks again
ASKER
I am back in town, worked great. thanks