• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Open a PPT using a wildcard character via VBA

sam77

New Member
Hi All,


Could anyone help me with this code please. Im not sure what im doing wrong here. But what im trying to do is to open a ppt file based on the name of the file. Basically "dept" in the below code is a variable where in the name can be any thing. The challenge is using a wild card. For example if the name of the file i want to search and open is " John Smith" and there are many files with the last name as Smith, i need to check for either John or Smith to be available in the file name and then if there is a match then open that file. Guess this would need a wildcard character, but im unable to crack it. Here is the code line where im stuck


Set desppt = newPowerPoint.Presentations.Open(Filename:="C:Documents and Settings" & Environ("username") & "My DocumentsEP - " & dept & Format(Range("A1"), "mm dd yy") & ".pptx", withwindow:=msoTrue)


Hope my question is clear. Please do let me know.


Thanks a ton!

Regards

Sam
 
Hi ,


Are you doing this in Powerpoint ?


If so , the use of Range("A1") is an error ; it needs to be fully qualified.


Also , in general , there should be a space between the keyword "new" and the keyword "Powerpoint".


Can you copy + paste the complete procedure ?


Narayan
 
You would need to use the FileScripting Object to first search for the existance of the PPT file, if found then use the code above to open the presentation.


~VijaySharma
 
Hi,


Here is the some additional code for your reference.


Sub SlideCopy()


Dim newPowerPoint As PowerPoint.Application

Dim newpres As PowerPoint.Presentation

Dim activeSlide As PowerPoint.slide

Dim sr As PowerPoint.ShapeRange

Dim ni As PowerPoint.ShapeRange

Dim fn As String

Dim SourceView, answer As Integer

Dim SourceSlides, NumPres, x As Long

Dim dept As String


On Error Resume Next

Set newPowerPoint = GetObject(, "PowerPoint.Application")

On Error GoTo 0


If newPowerPoint Is Nothing Then

Set newPowerPoint = New PowerPoint.Application

End If


sfn = InputBox("Enter the Filename that you want to open for slide mergers", "Merge Slides")

newPowerPoint.Visible = msoCTrue

Set srcppt = newPowerPoint.Presentations.Open(Filename:="C:Documents and Settings" & Environ("username") & "My DocumentsCESD " & sfn & " View " & Format(Range("A1"), "mm dd yy") & ".pptx", withwindow:=msoTrue)

dept = newPowerPoint.ActivePresentation.Slides(2).Shapes(1).TextFrame.TextRange.Text


NumPres = newPowerPoint.Presentations.Count


If NumPres = 0 Then


MsgBox "You must have at least one presentation open", _

vbCritical + vbOKOnly, "No Presentations Open"

End

End If


If NumPres > 2 Then

MsgBox "Too many open presentations. Only two presentations" _

& " may be open." & Chr(13) & "The active presentation is " _

& "the source and other presentation is the destination.", _

vbOKOnly + vbCritical, "Too Many Open Presentations"

End

End If


SourceView = newPowerPoint.ActiveWindow.ViewType


SourceSlides = newPowerPoint.ActivePresentation.Slides.Count


Set desppt = newPowerPoint.Presentations.Open(Filename:="C:Documents and Settings" & Environ("username") & "My DocumentsExecution Package - " & dept & Format(Range("A1"), "mm dd yy") & ".pptx", withwindow:=msoTrue)
 
Back
Top