Solved

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

Posted on 2014-09-29
7
581 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Test ddwrt:UserLookup 1 67
Post xml via PHP Soap Client 3 61
XSLT XML 4 28
Exporting Power Point (Mac 2011) to Word 2017 3 19
 Regular Expressions Microsoft Word has sophisticated search tools that can search for patterns. For example if you wanted to search for all UK phone numbers that followed a pattern of five digits, a space and then six digits you can easily do th…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
The viewer will learn how to edit text. This includes Font, Spacing, Resizing, Color, and other special text options.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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