Convert VBC code to C#

Posted on 2013-02-04
Medium Priority
Last Modified: 2013-03-04
I have a small section of VBA code which I need to convert/rewrite in C#.
Basically the code specifies the count, name and location of images which are to be used in a gallery on a custom Excel Ribbon:

Sub getBSCGalleryItemImages(control As IRibbonControl, index As Integer, ByRef image)
    Set image = LoadPicture("//images/report_snapshot_" & index + 1 & ".jpg")
End Sub
Sub getBSCGalleryItemCount(control As IRibbonControl, ByRef count)
        count = 3
End Sub

Open in new window

Thanks for the help

Question by:fjkilken
  • 2
  • 2
LVL 25

Expert Comment

ID: 38855182
It would be something like the following:
void getBSCGalleryItemImages(IRibbonControl control,int Index, ref image) {

    image = LoadPicture("//images/report_snapshot_" + int.parse(index + 1) + ".jpg");


void getBSCGalleryItemCount(IRibbonControl control, ref count) {

        count = 3;


Open in new window

Per your code I didn't know what type variable count was or Image, so those may have to be added.

Author Comment

ID: 38856096
doesn't look like that will work - "LoadPicture" method is not recognised
LVL 25

Accepted Solution

SStory earned 1000 total points
ID: 38856194
You will need a

using System.Drawing;

at the top of the module in C#

String path="//images/report_snapshot_" + int.parse(index + 1) + ".jpg";
Image image1 = Image.FromFile(path);

can load an image from a file.

Author Comment

ID: 38856245
let me take a look at incorporating that tomorrow

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
What to do if a split doesn't fit? Or a bunch of invoice lines must be rounded while the sum must match a total? It takes a little, but - when done - it is extremely easy to implement.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa‚Ķ

607 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