调用 Shell Explorer

问题描述 投票:0回答:1

我正在使用工作簿设计一个可保存在任何用户桌面上的 PDF。尽管代码在正确的位置创建了 pdf,但最后我尝试打开该文件夹,而不是打开创建的文件夹,而是打开用户的“文档”文件夹。你能发现我在这里做错了什么吗?

    Function Create_PDF()
    Dim GetDesktop As String
    Dim ws As Worksheet
    Dim ClientName As String, dt As String, FullName As String, fName As String, sep As String, cusip As String
    Dim myrange As String
    Dim MyTableRange As String
    Dim sfolderpath As String
    
    
    Set ws = ActiveSheet
        ClientName = ws.Range("I10").Value
        cusip = ws.Range("I11").Value
         
            ActiveSheet.PageSetup.PrintArea = "F5:N28"
    
 '*************Locates Desktop Folder for the User**************  
      
        Dim oWSHShell As Object
    
        Set oWSHShell = CreateObject("WScript.Shell")
        GetDesktop = oWSHShell.SpecialFolders("Desktop")
        Set oWSHShell = Nothing
        
 '**********************Creates the end folder*******************
        
        Set FindFolder = CreateObject("Scripting.FileSystemObject")
        sfolderpath = GetDesktop & "\Class Actions\"
        If FindFolder.FolderExists(sfolderpath) Then
        Else
           MkDir sfolderpath
        End If
        
    
    '*********** Formatting the File Name for the Export *************
    
        fName = sfolderpath & ClientName & " - Eligibility Report - " & cusip
            
        If Len(Dir(fName & ".pdf")) > 0 Then sep = " - "
        fName = fName & ".pdf"
        
    '***********Setting Export to PDF Parameters***********
    
        Application.PrintCommunication = False
        With Sheets("Starting Page").PageSetup
            .FitToPagesWide = 1
            .FitToPagesTall = False
        End With
        Application.PrintCommunication = True
           
            ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=fName, _
            Quality:=xlQualityStandard, IncludeDocProperties:=True, _
            IgnorePrintAreas:=False, OpenAfterPublish:=True
            
            
                    
    '************Opens Destination Folder to Retrieve File***********
    
       Call Shell("explorer.exe " & sfolderpath, vbNormalFocus)
        
    End Function
excel vba shell explorer
1个回答
0
投票

@FaneDuru 的这个答案非常有效:

shell "explorer.exe """ & GetDesktop & "\""", vbNormalFocus

© www.soinside.com 2019 - 2024. All rights reserved.