GetOpenFilename打开PowerPoint演示文稿后面的对话框

时间:2015-08-27 18:13:10

标签: excel powerpoint

我在powerPoint中使用VBA来更新我的PowerPoint中Excel对象的链接,一切运行良好。我唯一的问题是,有时选择文件对话框会在活动的Powerpoint后面打开,选择它的唯一方法是CTRL + ALT + Del并选择Excel文件选择器并将其设置为活动状态。有没有办法让它在打开时始终是活动的对话框?以下是我使用的代码:

Sub UpdateLinks()
Dim sld As Slide
Dim sh As Shape
Dim strNms As String
Dim intI As Integer
Dim strNewPath
Dim ExcelFile
Dim exl As Object
Set exl = CreateObject("Excel.Application")
'Set exl = exl.ActiveWindow
'exl.Active = True
 'Open a dialog box to promt for the new source file.
ExcelFile = exl.Application.GetOpenFilename(, , "Select Excel File")
'Go through every slide
For Each sld In ActivePresentation.Slides
    For Each sh In sld.Shapes
        If sh.Type = msoLinkedOLEObject Then
            With sh.LinkFormat
                strNms = .SourceFullName
                intI = InStr(1, strNms, "!")
                strNewPath = ExcelFile & Mid(strNms, intI, Len(strNms) - intI + 1)
                .SourceFullName = strNewPath
            End With
        End If
    Next sh
Next sld
ActivePresentation.UpdateLinks

End Sub

感谢。

1 个答案:

答案 0 :(得分:0)

建议:尝试使用此版本的文件选择器:

Sub FileDialogExample()
' Courtesy of John Wilson
' www.pptalchemy.co.uk

    Dim fd As FileDialog
    Dim sFilename As String

    Set fd = Application.FileDialog(msoFileDialogFilePicker)

    With fd
        .Filters.Clear
        .Filters.Add "Excel Files", "*.xls *.xlsx"
        .InitialFileName = Environ("USERPROFILE") & "\Desktop\"
        .AllowMultiSelect = False
        If .Show = True Then sFilename = .SelectedItems(1)
    End With
    'do whatever with sFilename
    MsgBox "You picked " & sFilename

End Sub