在Excel中读取文件路径VBA
问题描述:
我使用VBA从Excel中的某些图表每周创建一个PowerPoint。但是,第一张幻灯片需要来自PowerPoint创建的最后一周。在Excel中读取文件路径VBA
文件路径和名称都是变量,因为它们的标题中包含日期。我可以解释这一点,并用实际的文件名进行检查。它对我来说看起来是一样的。然而,当我试图打开我得到的ActiveX错误/运行时错误429.任何想法,将不胜感激
Sub CreateNewPres()
Dim ppApp As PowerPoint.Application
Dim ppPres As PowerPoint.Presentation
Dim objPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Dim ppTextbox As PowerPoint.Shape
Set ppApp = New PowerPoint.Application
ppApp.Visible = True
ppApp.Activate
Set ppPres = ppApp.Presentations.Add
todayDate = Date
myTextDate = Format(todayDate, "yyyy-mm-dd")
myFilePath = "C:\Desktop\Main\" & myTextDate
myFileName = "\Meeting_" & myTextDate & ".pptx"
myFile = myFilePath & myFileName
objPres=_
Presentations.Open(myFile)
objPres.Slides(1).Copy
ppPres.Slides.Paste (ppPasteEnchancedMetafile)
Set ppTextbox = ppSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, _
Left:=0, Top:=0, Width:=30, Height:=10)
With myTextBox.TextFrame.TextRange.Text = todayDate
End With
答
改变这一行的文件:
objPres = Presentations.Open(myFile)
这样:
Set objPres = ppApp.Presentations.Open(myFile)
这是答案的一半,ppPres.Slides.Paste(ppPasteEnchancedMetafile)'?如果您不参考幻灯片号码 –
,您也会在此处收到错误。未能正常工作。同样的错误。以防万一,我会发布其余的代码。 –
验证'myFile'是否包含有效的文件名。 –