0

I have created a code which select a PPT file from my system. But this is a hard code. How can I create a global code instead of hardcoding? My code is given below:

Sub PPTTest()
  Dim PPT As Object

  Set PPT = CreateObject("PowerPoint.Application")

  PPT.Presentations.Open "D:\Us\70\Desktop\Shaon\BOD.pptx", , , False

  ' Note that the file name and the module
  ' name are required to path the macro correctly.
  PPT.Run "BOD.pptx!Module1.KillSpecificSlide"

 End Sub

How to make this selection globally?

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
Shaon
  • 133
  • 1
  • 13
  • What do you mean with "global"? – Paul Ogilvie Feb 25 '19 at 08:29
  • @Paul Ogilvie it means I can choose any ppt file available in my system.Here in the code above my code name is BOD.pptx and its written in the code where as I want to create a code where I can choose any ppt file from my system – Shaon Feb 25 '19 at 09:05

1 Answers1

0

The following is an (incompete) example taken from one of my Excel macros:

Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogOpen)
With fldr
    .Title = "Select a File"
    .AllowMultiSelect = False
    .InitialFileName = ""
    If .Show <> -1 Then Exit Sub
    sItem = .SelectedItems(1)
End With
Set fldr = Nothing

sItem now contains the selected item. Use it in your PPT.Presentations.Open call.

Note: this code still must be in an MS-Office file (word, ppt, excel). To make such a macro "global" it must be in the startup template.

You can find or change the Startup location containing startup templates (in excel, but probably too in ppt) under Excel Options, Trust Center, Trust Center Settings.

Paul Ogilvie
  • 25,048
  • 4
  • 23
  • 41
  • This code works fine to choose the path name...After execution I got D:\Us\70\Desktop\Shaon\BOD.pptx...Now from this path if I just want to store only BOD.pptx in a variable and not the total path then how to do it? – Shaon Feb 25 '19 at 09:36
  • Use `Mid()`. But I strongly suggest you learn more about VB and read through the available functions and methods. There are more functions like Mid that can help you. – Paul Ogilvie Feb 25 '19 at 09:41