2016-10-12 45 views
0

(Excel和PowerPoint中2011适用于Mac)Excel的VBA调用宏的PowerPoint演示失败精细

我有打开PowerPoint和执行宏Excel宏。 如果我执行宏的PowerPoint演示直接它工作正常,但如果我从Excel宏调用执行它,它失败,运行时错误“68”:设备不可用

正是这种循环之前:

Dim strfilee As String 


mydir = ":tmp" 
strpath = mydir & ":" 
strfilee = Dir(strpath) <--- Failing on this line 


''''Loop through each file in the folder to find the one with the OS parameters 

    i = 0 

    Do While Len(strfilee) > 0 
    cellplace = "A" & i 

     If Right(strfilee, 11) = "params.pptx" Then 
     lspace = InStr(1, strfilee, "_", vbTextCompare) 
     target_name = Trim(Left(strfilee, lspace - 1)) 
     sc_file_name = "tmp" & ":" & strfilee 

       With ActivePresentation 
        number_slides = .Slides(.Slides.Count).SlideNumber 
        End With 
       ActivePresentation.Slides.InsertFromFile sc_file_name, number_slides 


     End If 
     strfilee = Dir 
     i = i + 1 

    Loop 
+0

所以你的路径变量被设置为“:tmp:”。无论在哪种情况下,我都看不出它是如何工作的。不应该是本地驱动器参考,例如“C:\ tmp \”或网络位置,如“\\ myServer \ tmp \”。根据MSDN,Dir函数将PathName参数作为“指定文件名,目录或文件夹名称或驱动器卷标的字符串表达式”。 –

+0

Hello JamieG,谢谢你的回答。 :tmp只是对演示文稿所在的实际文件夹中tmp文件夹的引用。我会尝试将其改为全球,看看这是否可能是根本原因。谢谢! – Diego

+0

解决了这个问题。当您直接在Powerpoint上执行宏时,相对路径“:tmp:”正常工作。如果你想从excel中调用powerpoint宏,你必须把全局路由(activepresentation.path $“:tmp:” – Diego

回答

0

使用Dir函数时请尝试使用完全限定的路径。