williecg
asked on
Refresh links in powepoint presentation
I need vba script that will run in msaccess that opens a power point presentation, update the links and saves the presentation
(office 2016)
presentation name: f:\test.pptx
I am a newbe so I would appreciate it if the script contains all code to execute.
Thanks,
WillieCg
(office 2016)
presentation name: f:\test.pptx
I am a newbe so I would appreciate it if the script contains all code to execute.
Thanks,
WillieCg
What links are you referring to? Pictures, Excel data etc.?
ASKER
chart links to excel, however the general case is all links. I found the below, but I do not know how to put it all together to make a script. thanks,
Example
This example updates all OLE links in the active presentation.
VB
ActivePresentation.UpdateL inks
https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.updatelinks
Example
This example updates all OLE links in the active presentation.
VB
ActivePresentation.UpdateL
https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.updatelinks
Any particular reason you want to do this in MS Access?
Or can it also be done via Word, Excel, or PowerPoint VBA code?
Or can it also be done via Word, Excel, or PowerPoint VBA code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
to: Sam JacobsDirector of Technology Development, IPM
The bulk of my application is in access. Excel, and powerpoint are data staging and presentation.
thanks,
WillieCg
The bulk of my application is in access. Excel, and powerpoint are data staging and presentation.
thanks,
WillieCg
If you don't want to hard-code the file name, replace line 14 above with:
In line 29, you'll also need to replace FILE_PATH_AND_NAME with PPTtoOpen.
Dim PPTtoOpen As String
PPTtoOpen = selectFile("PowerPoint", "PPT Files (*.pptx*)", "*.ppt*")
If PPTtoOpen = "" Then Exit Sub
... and then add the following routine:Function selectFile(strFileType As String, strExtDesc As String, strFileExt As String) As String
Dim dlg As Office.FileDialog
Set dlg = Application.FileDialog(msoFileDialogFilePicker)
With dlg
.Title = "Please select the " & strFileType & " to open:"
.Filters.Clear
.Filters.Add strExtDesc, strFileExt
If .Show = True Then
selectFile = .SelectedItems(1)
Else
selectFile = ""
End If
End With
End Function
In line 29, you'll also need to replace FILE_PATH_AND_NAME with PPTtoOpen.
ASKER
to: Jamie GarrochPowerPoint Consultant & Developer
Your solution seemed to work, it processed in powerpoint about 45 seconds, which is what it takes when I manually update links.
However, the presentation was NOT updated.
I am going to put a simple spreadsheet and simple powerpoint together to see if that will work if I can make that work, I know the problem is with my excel or powerpoint files.
I will update you later.
thanks
Your solution seemed to work, it processed in powerpoint about 45 seconds, which is what it takes when I manually update links.
However, the presentation was NOT updated.
I am going to put a simple spreadsheet and simple powerpoint together to see if that will work if I can make that work, I know the problem is with my excel or powerpoint files.
I will update you later.
thanks
Did you copy the macro before it had the oPres.Save line which I forgot originally and then added about 5 mins later?
Here's a heavily modified update with debugging, window mode and pause before close.
You can set the DEBUG_MODE to True to use this special mode. You then run either the MainMacro (fixed text file) or TestMacro (file dialog) macro depending on how you want to test.
When in debug mode the PowerPoint file will open in a window, the links will be updated and then execution will stop (pause) until you press F5 to continue. When paused, you can check the content in the PowerPoint file to make sure it's been updated as expected. Note that if a link is broken, or a linked file is not where it's expected then this won't be detected.
You can set the DEBUG_MODE to True to use this special mode. You then run either the MainMacro (fixed text file) or TestMacro (file dialog) macro depending on how you want to test.
When in debug mode the PowerPoint file will open in a window, the links will be updated and then execution will stop (pause) until you press F5 to continue. When paused, you can check the content in the PowerPoint file to make sure it's been updated as expected. Note that if a link is broken, or a linked file is not where it's expected then this won't be detected.
Option Explicit
' Set to true to see debug messages, open file with a window and pause before closing it
' Set to false for production
Private Const DEBUG_MODE = False
' Macro to call the main procedure via a file dialog selection
Public Sub MainMacro()
Call UpdatePowerPointLinks
End Sub
' Macro to call the main procedure with a fixed test file (no file dialog)
Public Sub TestMacro()
Call UpdatePowerPointLinks("f:\test.pptx")
End Sub
' ==================================================================
' VBA procedure to update links of a specified PowerPoint files
' Will run in any VBE e.g Excel, Access, PowerPoint, Word etc. since
' it uses late binding for the objects.
' Author : Jamie Garroch of YOUpresent, http://youpresent.co.uk/
' Date : 28OCT2018
' ==================================================================
Private Sub UpdatePowerPointLinks(Optional tFilePathAndName As String = "")
Dim oPP As Object ' Late bound PowerPoint Application object
Dim oPres As Object ' Late bound Presentation object
If tFilePathAndName = "" Then tFilePathAndName = SelectFile("PowerPoint", "All PowerPoint Files", "*.ppt*;*.pot*;*.pps*")
On Error Resume Next
' Try to get an existing instance of PowerPoint
Set oPP = GetObject(, "PowerPoint.Application")
' If none exists, create a new one
If Err Then Err.Clear: Set oPP = CreateObject("PowerPoint.Application")
If Err Then
MsgBox "Couldn't find/start PowerPoint.", vbCritical + vbOKOnly, "PowerPoint Unavailable"
Exit Sub
End If
If DEBUG_MODE Then
Debug.Print "opening " & tFilePathAndName & "..."
Set oPres = oPP.Presentations.Open(Filename:=tFilePathAndName, ReadOnly:=False, Untitled:=False, WithWindow:=True)
Else
Set oPres = oPP.Presentations.Open(Filename:=tFilePathAndName, ReadOnly:=False, Untitled:=False, WithWindow:=False)
End If
DoEvents
' Update all OLE links in the presentation
If DEBUG_MODE Then Debug.Print "updating OLE links..."
Debug.Print oPres.UpdateLinks
If DEBUG_MODE Then Debug.Print "saving file..."
oPres.Save ' Could also use SaveAs or SaveCopyAs if overwrite is not what's needed
If DEBUG_MODE Then Debug.Print "closing file..."
If DEBUG_MODE Then Stop ' When stopped, press F5 to continue after checking the PowerPoint file
oPres.Close
' Clean up
Set oPres = Nothing: Set oPP = Nothing
Debug.Print "UpdatePowerPointLinks finished."
End Sub
' Get the user to select a PowerPoint file using the File Dailog window
Private Function SelectFile(tFileType As String, tExtDesc As String, tFileExt As String) As String
Dim oFileDlg As Office.FileDialog
Set oFileDlg = Application.FileDialog(msoFileDialogFilePicker)
With oFileDlg
.Title = "Please select the " & tFileType & " file to open:"
.Filters.Clear
.Filters.Add tExtDesc, tFileExt
If .Show = True Then
SelectFile = .SelectedItems(1)
Else
SelectFile = ""
End If
End With
End Function
ASKER
to: Jamie Garroch
yes, the save command made it work properly.
thanks so much this is exactly what I needed.
WillieCg
yes, the save command made it work properly.
thanks so much this is exactly what I needed.
WillieCg