我必须将大量Excel图表发布到特定的PowerPoint文档中,并且我在Excel VBA中构建一个宏来为我完成。
我能够正确打开我要更新的PowerPoint演示文稿,但是我不知道如何设置我刚刚打开的演示文稿到名为MyPresentation
的变量。
Dim myPresentation As PowerPoint.Presentation
Dim PowerPointApp As PowerPoint.Application
PowerPointApp.Presentations.Open Filename:="obscured filepath and name"`
显然还有一些额外的代码,但是我试图将我刚刚在第3行中打开的演示文稿设置为MyPresentation
变量,以便我可以引用刚刚打开的文档。 / p>
答案 0 :(得分:5)
我最终找到了MVP Andy Pope的解决方案。
针对未来用户的一些相关代码段。 (仅供我参考,当我遇到问题时,我的PPT已经可见了)
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
'Easier to define manually set links up front so it's easier to change/modify
DestinationPPT = "C:\yourfilepath\yourfilename.pptx"`
查看电子表格大师从Excel VBA打开PPT的指南
然后:
Set myPresentation = PowerPointApp.Presentations.Open(DestinationPPT)
答案 1 :(得分:1)
首先,您必须为使用ppt文件铺平道路, 我做了什么:
Dim DestinationPPT As String
Dim PowerPointApp As PowerPoint.Application
Dim myPresentation As PowerPoint.Presentation
Set PowerPointApp = CreateObject("PowerPoint.Application")
DestinationPPT = "path"
PowerPointApp.Presentations.Open (DestinationPPT)
答案 2 :(得分:0)
这个为我工作:
- (NSString *)deviceModel {
size_t size;
// Get buffer size to allocate
if (sysctlbyname("hw.machine", NULL, &size, NULL, 0) == -1) {
// syscall failed, return nil or handle it your way
NSLog(@"syscall hw.machine failed with error %d", errno);
return nil;
}
// Allocate memory for syscall result
char *buffer = malloc(size);
if (buffer == NULL) {
NSLog(@"malloc failed with error %d", errno);
return nil;
}
// Get the actual value
if (sysctlbyname("hw.machine", buffer, &size, NULL, 0) == -1) {
// syscall failed, return nil or handle it your way
NSLog(@"syscall hw.machine failed with error %d", errno);
// Buffer already allocated, free it to avoid leaks
free(buffer);
return nil;
}
// Create a NSString from C string
NSString *deviceModel = [NSString stringWithCString:buffer encoding:NSUTF8StringEncoding];
// Free memory, bytes were copied in the stringWithCString:encoding:
free(buffer);
return deviceModel;
}
在打开前将visible设置为true。否则对我不起作用
答案 3 :(得分:0)
我试图创建一个excel文件,该文件可以基于特定的工作表生成预定义的PowerPoint演示文稿,并且excel文件中的值不同。
我的问题是我部门的每个人都应该能够下载并运行excel文件。
在vba中定义演示文稿并不适合所有人,因为并非在每台计算机/ excel程序上都激活了此操作所需的引用。
Createobject为我解决了问题。 这是我正在谈论的代码:
Dim pptApp as object
Dim strpath as string
strpath = ThisWorkbook.Path & "\Test_Dummy.pptx"
Set pptApp = createobject("Powerpoint.application")
pptApp.Presentations.Open Filename:=strpath, readonly:=false, untitled:=true, withwindow:=true
没有的工作是这样的:
Dim pptApp as Powerpoint.Application
或
Dim pptApp as object
Set pptApp = New Powerpoint.Application
未在vba中设置所需的引用