0

Am developing an ad-din for power Point , for that i need to insert a image from Local disk or need to paste the image from clipboard to power point using c#.But here i was able to do both the functions without adding hyper-link,But i need the hyper-link to be also added.

used to insert a picture to PPT:

 slide.Shapes.AddPicture(path, Microsoft.Office.Core.MsoTriState.msoFalse,
                      Microsoft.Office.Core.MsoTriState.msoTrue, shape.Left, shape.Top, shape.Width, shape.Height);

Used to paste a picture from clip Board:

slide.Shapes.Paste();

both the above process are working.but how to insert an image with hyper-link?Been struck here for past 2 days.

  PPT.Shape  shap1=   slide.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal, 50,50,250,50);


                PPT.TextRange objTextRng;
                objTextRng = shap1.TextFrame.TextRange;
                objTextRng.Text = txt;

                objTextRng.ActionSettings[PPT.PpMouseActivation.ppMouseClick].Hyperlink.Address = @"http://google.com";

in the above mentioned way am inserting hyper-link to the text in PPT , Likewise i need to add hyper-link to am image in PPT. Thanks

Dah Sra
  • 4,107
  • 3
  • 30
  • 69

1 Answers1

1

I believe the code you are looking for is:

pic.ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address = @"http://www.google.com/";

And the whole method that creates new presentation with Image with hyperlink is:

using Microsoft.Office.Interop.PowerPoint;
...

    private void AddImageWithHyperlink()
    {
        Microsoft.Office.Interop.PowerPoint.Application objApp = new Microsoft.Office.Interop.PowerPoint.Application();
        objApp.Visible = Microsoft.Office.Core.MsoTriState.msoTrue;
        Presentations objPresSet = objApp.Presentations;
        Presentation objPres = objPresSet.Add(Microsoft.Office.Core.MsoTriState.msoTrue);            
        Slide slide =
            objPres.Slides.Add(
            objPres.Slides.Count + 1,
            PpSlideLayout.ppLayoutPictureWithCaption);

        // Shapes[2] is the image shape on this layout.
        Shape shape = slide.Shapes[2];

        Shape pic = slide.Shapes.AddPicture(@"C:\Users\Public\Pictures\Sample Pictures\koala.jpg",
        Microsoft.Office.Core.MsoTriState.msoFalse,
        Microsoft.Office.Core.MsoTriState.msoTrue,
        shape.Left, shape.Top, shape.Width, shape.Height);

        pic.ActionSettings[PpMouseActivation.ppMouseClick].Hyperlink.Address =@"http://www.google.com/";
    }

Also check your Microsoft.Office.Interop.PowerPoint.dll version, should be 14 or higher...

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
  • 1
    Am having some doubts ..can you please guide me..!! – Dah Sra Jul 21 '14 at 12:20
  • Really first check what your version of PIA (referenced Microsoft.Office.Interop.PowerPoint.dll) is. Use most current version. I tested this code with PowerPoint 2013 and PIA v14.0 – Vojtěch Dohnal Jul 21 '14 at 12:22
  • I believe that what you did wrong is, that you set ActionSettings not on inserted Shape (picture) but on TextBox – Vojtěch Dohnal Jul 21 '14 at 12:25
  • 1
    Thanks and now its working. Can you please tell me how to get the active slide , i dont want to create a new slide and insert the picture . I need to insert the picture in the current active slide – Dah Sra Jul 21 '14 at 12:31
  • 1
    Slide x = objApp.ActiveWindow.View.Slide; or objApp.ActivePresentation.Slides[1]; or objApp.ActivePresentation.Slides.FindBySlideID. – Vojtěch Dohnal Jul 21 '14 at 12:35
  • Thanks and its working. can you please help me in this [link]http://stackoverflow.com/questions/24883073/how-to-read-the-hyper-link-of-an-image-in-power-point-using-c-sharp – Dah Sra Jul 22 '14 at 09:01