In order to open an existing pptx file and add a new slide to the deck using VBA, I'm referring to an earlier post. The below link is to the post, but, when I try to execute the sub I obtain a "Object Needed" run-time problem after selecting the pptx. I've also provided the code that I tried executing, based on the relevant thread. Any idea how to resolve this error?
Sub Test()
With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False 'only allows the user to select one file
' Set the title of the dialog box.
.Title = "Select the File." 'Put any text to help the user choose the correct file
'clear filters then add pptx filter
.Filters.Clear
.Filters.Add "PowerPoint files", "*.pptx" ' This can be any file extension to filter the choices
' Show the dialog box. If the .Show method returns True, the
' user picked at least one file. If the .Show method returns
' False, the user clicked Cancel.
If .Show = True Then
fxname = .SelectedItems(1)
End If
End With
Set opres = Presentations.Open(fxname, False, False, True) 'opres is the variable for the choosen file
opres.Windows(1).Activate 'Activates that presentation.
End Sub
When debugging, the Set opres = Presentations.Open(fxname, False, False, True) is what's highlighted as an error.