Solved

Creating custom ribbon gallery in PowerPoint with VBA - specifying image location

Posted on 2014-09-29
7
625 Views
Last Modified: 2014-10-17
Hi

I am coding a custom gallery which I would like to display all the images in a specific network folder. I have coded the XML fine, but am having trouble with the VBA for the "GetItemImage" element. I have JPGs in my file, but it doesn't seem to be finding the file names, just the folder location.

Please can you tell me where i am going wrong with this. My code is as follows:

Sub PL_image(control As IRibbonControl, Index As Integer, ByRef image)

Dim stpath As String
Dim imgpath As String
Dim imgname As String

stpath = "\\MYPATH\" & imgname 'Path to Picture Library

imgpath = Left(stpath, InStrRev(stpath, ".") - 1)

Set image = LoadPicture(imgpath & ".jpg")

End Sub
0
Comment
Question by:Sim Kuch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 40351522
Stand by.....
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 40351545
How do you place the images into the ribbon. Do you just use "Insert" or "Insert and link"?
0
 
LVL 13

Expert Comment

by:Chris Raisin
ID: 40351559
Forget my last question. I am not very familiar with iRibbonControls.

Here is a reference which MAY HELP IF YOU READ THROUGH THE CODE:
http://gregmaxey.mvps.org/word_tip_pages/dynamic_ribbon_menu.html

The "callbacks" to objects in the ribbon may be able to get what you are after.

At the moment your code has an empty string for " imgname" and a value is never assigned to it.
You must find a way of getting the filename for an image from the ribbons images.
It is a shame you are using "image" rather than "graphic" since graphics has a property "filename").

I better not say too much more since I may be just saying "rubbish", but perhaps the link I have supplied might lead you somewhere.

If I discover anything else I will get back to you. Let me know of any developments.

Cheers

Chris (Melbourne-Australia)
0
Stressed Out?

Watch some penguins on the livecam!

 
LVL 23

Expert Comment

by:JSRWilson
ID: 40356399
You need to use a dynamicGallery not a DynamicMenu and you need to post your XML

XML should look something like this

    <gallery id="mygall" label="NEW" imageMso="HappyFace" size="large" onAction="runGall" getItemHeight="getH" getItemWidth="getW"  
     columns="5" rows="4" getItemCount="getCount" getItemImage="getimage" getItemID="getID"  />

GetItemImage does not exist it's getItemImage (case is vital in XML)
0
 

Accepted Solution

by:
Sim Kuch earned 0 total points
ID: 40356489
Thanks for your comment - the xml is working fine - I was using getItemImage, I typed it incorrectly here

<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnSKload">
  <ribbon startFromScratch="false">
    <tabs>
      <tab id="Custom_tab" label="SharePoint" keytip="Y">
        <group id="SharePoint" label="SharePoint">
          <gallery id="PictureLib"
            columns="4"
             label="Insert image from SharePoint"
            size="large"
            imageMso="ClipArtInsert"
            itemHeight="100"
            itemWidth="100"
            getItemCount="PL_count"
            getItemImage="PL_image"
            onAction="PL_insert">
          </gallery>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

I have succeeded in getting the pictures to show but it takes a very long time to run so I'm not sure if I've done it correctly. I used an array:

Sub PL_image(control As IRibbonControl, Index As Integer, ByRef image)

Dim fso As Object
Dim objfolder As Object
Dim obj, objfile As Object
Dim strpath As String
Dim imgpath As String
Dim imgname As String
Dim imgarray() As String
Dim x As Integer
Dim i As Double

strpath = "\\MYPATH\" 'Path to Picture Library

Set fso = CreateObject("Scripting.FileSystemObject")
Set objfolder = fso.GetFolder(strpath)
x = objfolder.Files.count
i = 0

ReDim imgarray(1 To x)
    For Each objfile In objfolder.Files
        imgname = objfile.Name
        imgname = Left(imgname, InStrRev(imgname, ".") - 1)
        i = i + 1
        imgarray(i) = imgname
    Next

Set image = LoadPicture(strpath & imgarray(Index) & ".jpg")
   
End Sub
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 40356499
Pretty sure it will always be slow on a network.
0
 

Author Closing Comment

by:Sim Kuch
ID: 40386219
This solution works, but it is very slow. This might always be the case when pulling pictures from a network though - I'm not sure. It's not really a viable solution for use in a corporate tool though, so I have downgraded it.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

724 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question