Solved

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

Posted on 2014-09-29
7
544 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
  • 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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction In all recent versions of PowerPoint it is possible to trigger animations. This means the animation takes place when a certain shape is clicked. This allows you to run animation “on demand” and outwith the normal sequence of mouse cl…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now