Louie O
Louie O

Reputation: 41

Powepoint VBA AddPicture - Grant File Access

I'm trying to create a dynamic presentation. The presentation will showcase multiple projects, and those projects are shown as thumbnails (in grid) on a slide. Those thumbnails are added already in the slide. Once you click on a thumbnail, it will take you to the next slide loading 5 dynamically called images (via code - .AddPicture).

Now, I got that part nailed down. works perfectly. However, once I share the folder to someone, or even move the folder to a different location in my drive, I get a message that I need to Grant Access to a file. Which is annoying.

Please take note that:

  1. I made sure I grabbed the correct path to the file
  2. I made sure to check if the user is a mac-user or windows-user using "if Mac"
  3. I've tried:

here's a very simple test code I did (file path is for a mac-user):

Dim tgtSlide As Slide
Dim prj As Shape

Sub thumbClick()
    Dim sld As Slide
    Dim picPath As String

    Set sld = ActivePresentation.SlideShowWindow.View.Slide
    Set tgtSlide = ActivePresentation.Slides(sld.SlideIndex + 1)

    'get the presentation save path first
    picPath = ActivePresentation.Path
    'define the image full path
    picPath = picPath & "/PRJ1-IMG1.jpg"

    'add a linked image/shape to target slide
    Set prj = tgtSlide.Shapes.AddPicture(picPath, msoTrue, msoTrue, Left:=50, Top:=50)
    prj.LinkFormat.Update

    'goes to the target slide
    ActivePresentation.SlideShowWindow.View.GotoSlide (tgtSlide.SlideIndex)
End Sub

Upvotes: 1

Views: 170

Answers (1)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

Regarding the missing Application.PathSeparator in PPT, you can do this instead:

Dim PATHSEP as String
#If Mac Then
  PATHSEP = "/"
#ELSE
  PATHSEP = "\"
#End If

Then use PATHSEP in your code when you need the path separator character

Upvotes: 1

Related Questions