【问题标题】:visual basic in powerpointsPowerPoint中的视觉基础
【发布时间】:2014-08-21 23:04:52
【问题描述】:

我有时会在 Visual Basic 中为 Excel 创建宏。但我从来没有将它用于 PowerPoint。我有一个带有很多图片的幻灯片。图片都在一个目录中。有时我会更改目录中的图片保留其原始名称。显然在 PowerPoint 中没有办法刷新图片的新版本。但我可以右键单击图片并选择相同的路径“更改图片”。无论如何,我的图片太多,我必须经常更改文件。所以我想知道是否有办法使用visual basic。我可以使用目录中文件的名称创建一个向量,并将名称与它们在 ppt 中出现的顺序相同。然后创建一个再次更改所有路径的宏,以便图片将升级。我不知道我可以使用的代码。有人可以帮助我吗?

【问题讨论】:

  • "显然在 PowerPoint 中没有办法刷新新版本的图片。"不是这样。将图片插入 PPT 时,单击“插入”按钮旁边的箭头,选择“链接图片”。然后,如果图片发生变化,每当您再次打开 PPT 文件时,PPT 都会使用新版本。如果出于某种不适合您的原因,请说出来;使用 VBA 还有其他方法。

标签: excel powerpoint office-interop vba


【解决方案1】:

我不知道如何用“宏”来做到这一点 但! 您可以使用Office Interop - 并对其进行编码。 看看这个网站: http://www.free-power-point-templates.com/articles/how-to-create-a-powerpoint-presentation-using-c-and-embed-a-picture-to-the-slide/ 基本上你可以编写一个.Net 程序,通过Office Interop 来实现这一点

希望这会有所帮助...

编辑: 上面链接的主要代码部分:

string pictureFileName = "C:\\temp\\example.jpg"; 

Application pptApplication = new Application();

Microsoft.Office.Interop.PowerPoint.Slides slides;
Microsoft.Office.Interop.PowerPoint._Slide slide;
Microsoft.Office.Interop.PowerPoint.TextRange objText;

// Create the Presentation File
Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);

Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

// Create new Slide
slides = pptPresentation.Slides;
slide = slides.AddSlide(1, customLayout);

// Add title
objText = slide.Shapes[1].TextFrame.TextRange;
objText.Text = "FPPT.com";
objText.Font.Name = "Arial";
objText.Font.Size = 32;

objText = slide.Shapes[2].TextFrame.TextRange;
objText.Text = "Content goes here\nYou can add text\nItem 3";

Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
slide.Shapes.AddPicture(pictureFileName,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue,shape.Left, shape.Top, shape.Width, shape.Height);

slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "This demo is created by FPPT using C# - Download free templates from http://FPPT.com";



pptPresentation.SaveAs(@"c:\temp\fppt.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
//pptPresentation.Close();
//pptApplication.Quit();

【讨论】:

    猜你喜欢
    • 2013-04-02
    • 1970-01-01
    • 2012-12-22
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 2016-05-28
    • 1970-01-01
    相关资源
    最近更新 更多