隐藏宏过程中发生的所有任务

时间:2015-01-11 02:34:09

标签: vba excel-vba batch-file excel

我想隐藏在Excel工作簿前面发生的以下任务:

  1. 隐藏Excel工作簿前面的文件复制过程窗口(来自解压缩过程) (###注意:复制过程的窗口有时出现,有时不出现)..请在下面找到它的示例截图: enter image description here

  2. 隐藏Excel工作簿前面的cmd提示进程窗口(来自.bat文件)

  3. 我们如何隐藏上述两个任务,并以某种方式将其置于工作簿之后。

    我的完整代码的一部分如下:

    Option Explicit
    
    #If VBA7 Then
        Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
        (ByVal pCaller As LongPtr, ByVal szURL As String, ByVal szFileName As String, _
        ByVal dwReserved As LongPtr, ByVal lpfnCB As LongPtr) As LongPtr
    #Else
        Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
        (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, _
        ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
    #End If
    
    Sub Open_Dialog()
    
    'Disable Screen Updating and Events
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
        Dim fd As Office.FileDialog
        Dim sFolderName As String
        Dim DownloadFile$
        Dim URL$
        Dim LocalFilename$
        Dim done
        Dim ZipFolderAndFileName As Variant
        Dim FileNameFolder As Variant
        Dim FSO As Object
        Dim oApp As Object
        Dim aFile As String
        Dim txtFileName As String
    
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'Use File Picker To Pick a File Name
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Set fd = Application.FileDialog(msoFileDialogFilePicker)
    
        With fd
    
          .AllowMultiSelect = False
    
          ' Set the title of the dialog box.
          .Title = "Please select a file."
    
          ' Clear out the current filters, and add our own.
          .Filters.Clear
          .Filters.Add "Executable File", "*.exe"
          .Filters.Add "Word 97-2003 Doc File", "*.doc"
          .Filters.Add "Word Doc File", "*.docx"
          .Filters.Add "Text File", "*.txt"
          .Filters.Add "All Files", "*.*"
    
          ' Show the dialog box. If the .Show method returns True, the
          ' user picked at least one file. If the .Show method returns
          ' False, the user clicked Cancel.
          If .Show <> -1 Then
            Exit Sub
          End If
    
          txtFileName = .SelectedItems(1) 'replace txtFileName with your textbox
        End With
    
        'Get the Folder Name from the file name (the file name itself is not used)
        'Append a trailing backslash to the Folder Name if needed
        sFolderName = LjmExtractPath(txtFileName)
        If Right(sFolderName, 1) <> "\" Then
          sFolderName = sFolderName & "\"
        End If
    
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'Download the .zip file to the destination folder
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        DownloadFile$ = "pads_strings.zip"
        URL$ = "http://sagamusix.de/sample_collection/" & DownloadFile
        LocalFilename$ = sFolderName & DownloadFile
        done = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    
        If done = 0 Then
          'Do nothing
        Else
          MsgBox "Couldn't connect to the internet. Please check you internet connection!"
          Exit Sub
        End If
    
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'Extract the files from the zip file to the Destination Folder
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
        'Create the 'Variant' names required by oApp.Namespace
        FileNameFolder = sFolderName
        ZipFolderAndFileName = LocalFilename$
    
    
        Set oApp = CreateObject("Shell.Application")
        oApp.Namespace(FileNameFolder).CopyHere oApp.Namespace(ZipFolderAndFileName).items
    
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        'Delete the temporary files
        'Delete the downloaded .zip file
        'Clear object pointers
        ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        On Error Resume Next
        Set FSO = CreateObject("scripting.filesystemobject")
        FSO.deletefolder Environ("Temp") & "\Temporary Directory*", True
    
        aFile = LocalFilename
        If Len(Dir$(aFile)) > 0 Then
          Kill aFile
        End If
    
        Set fd = Nothing
        Set oApp = Nothing
    
        Dim Batch_File As String
        Batch_File = FreeFile()
        Open ThisWorkbook.path & "BatchFile.bat" For Output As #Batch_File
        Print #Batch_File, "cd "
        Print #Batch_File, "waitfor /t 5 simon"
        Close #Batch_File
        Batch_File = Shell(ThisWorkbook.path & "BatchFile.bat", vbMaximizedFocus)
    
    'Disable Screen Updating and Events
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    
    End Sub
    
    Public Function LjmExtractPath(sPathAndName As String)
      'This extracts the path with a trailing '\'
    
      LjmExtractPath = Left(sPathAndName, InStrRev(sPathAndName, "\"))
    
    End Function
    

    实际上,cmd提示进程在.bat文件中有很多其他任务。我只提供了一些。

    我尝试过使用下面的代码但是徒劳无功..它并不隐藏上面提到的那两项任务:

    Application.EnableEvents = False
    Application.ScreenUpdating = False
    'my code
    Application.ScreenUpdating = True
    Application.EnableEvents = True
    

    附件是我的.bat文件。请在下面找到相关链接。 click here to download my .bat file

0 个答案:

没有答案