2015-04-24 72 views
1

我想知道是否有人可以幫助我。VBA中心用戶窗體在活動屏幕上

我正在使用下面的'Extract'代碼,它運行在點擊一個按鈕上,也可以看到,使用滾動進度條顯示'Splash'窗體。

Private Sub btnFetchFiles_Click() 

    Dim j As Integer 

    'Display the splash form non-modally. 
    Set frm = New frmSplash 
    frm.TaskDone = False 
    frm.prgStatus.Value = 0 
' frm.Show False 

    For j = 1 To 1000 
     DoEvents 
     Next j 

     iRow = 20 
     fPath = "\\c\s\CAF1\Dragon Mentor Group\Dragon Scripts\Current\April 2015" 
     If fPath <> "" Then 
      Set FSO = New Scripting.FileSystemObject 
      frm.prgStatus.Value = 10 
      If FSO.FolderExists(fPath) <> False Then 
       frm.prgStatus.Value = 20 
       Set SourceFolder = FSO.GetFolder(fPath) 
       IsSubFolder = True 
       frm.prgStatus.Value = 30 
       Call DeleteRows 
       frm.prgStatus.Value = 40 
       If AllFilesCheckBox.Value = True Then 
        frm.prgStatus.Value = 50 
        Call ListFilesInFolder(SourceFolder, IsSubFolder) 
        frm.prgStatus.Value = 60 
        Call ResultSorting(xlAscending, "C20") 
        frm.prgStatus.Value = 70 
       Else 
        Call ListFilesInFolderXtn(SourceFolder, IsSubFolder) 
        frm.prgStatus.Value = 80 
        Call ResultSorting(xlAscending, "C20") 
        frm.prgStatus.Value = 90 
       End If 
       Call FormatCells 
       lblFCount.Caption = iRow - 20 
       frm.prgStatus.Value = 100 
      End If 
     End If 
frm.TaskDone = True 
     Unload frm 
'The row below creates a 'On Screen' message telling the user that the workbook has been built. 
     iMessage = MsgBox("All the files have been extracted", vbOKOnly) 
'The row below automatically takes the user to the "Launch Sheet". 
    End Sub 

因爲我使用的是雙顯示器我一直在研究如何中心閃屏ONT「有效Window'and的很多帖子,導致我用下面的代碼中的一個:

Private Sub UserForm_Initialize() 

    Me.BackColor = RGB(174, 198, 207) 
     With frmSplash 
      .StartUpPosition = 0 
      .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width) 
      .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height) 
    .Show 
End With 
End Sub 

現在我遇到的問題是,雖然'閃屏'屏幕是可見的,現在集中到活動窗口提取宏不再工作,我真的不知道爲什麼。

我只是想知道是否有人可以看看這個請讓我知道我出了什麼問題。

許多的感謝和親切的問候

克里斯

+0

如果你把一個斷點「對於j = 1到1000「是否被稱爲? – Steven

+0

嗨@Steven,謝謝你花時間回到我身邊。不幸的是,這並沒有改變一切。代碼似乎陷入了Initialize腳本中的'.show'。親切的問候。 Chris – IRHM

回答

1

我只是想發佈我的工作解決方案,它建立在我會寫作的東西上,工作同事能夠完成。

的代碼如下:

Private Sub UserForm_Initialize() 

    Me.BackColor = RGB(174, 198, 207) 
End Sub 

Private Sub Workbook_Open() 

    Dim j As Integer 

    'Display the splash form non-modally. 
    Set frm = New frmSplash 
    With frm 
     .TaskDone = False 
     .prgStatus.Value = 0 
     .StartUpPosition = 0 
     .Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width) 
     .Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height) 
     .Show False 
    End With 

    For j = 1 To 1000 
     DoEvents 
     Next j 

     iRow = 17 
     fPath = "\\c\s\CAF1\Dragon Mentor Group\Dragon Scripts\Current\April 2015" 
     If fPath <> "" Then 
      Set FSO = New Scripting.FileSystemObject 
      frm.prgStatus.Value = 15 
      If FSO.FolderExists(fPath) <> False Then 
       frm.prgStatus.Value = 30 
       Set SourceFolder = FSO.GetFolder(fPath) 
       IsSubFolder = True 
       frm.prgStatus.Value = 45 
       Call DeleteRows 
       frm.prgStatus.Value = 60 
        Call ListFilesInFolder(SourceFolder, IsSubFolder) 
        frm.prgStatus.Value = 75 
       Call FormatCells 
       frm.prgStatus.Value = 100 
      End If 
     End If 
frm.TaskDone = True 
     Unload frm 
'The row below creates a 'On Screen' message telling the user that the workbook has been built. 
     iMessage = MsgBox("All the files have been extracted", vbOKOnly) 
'The row below automatically takes the user to the "Launch Sheet". 
End Sub 

非常感謝和親切的問候

克里斯

1

你是要顯示窗體爲模式,它停止後臺代碼執行的問題。

在窗體屬性中將ShowModal設置爲false。

+0

嗨@Steven,謝謝你,這當然會使窗體中心正確,謝謝。不幸的是,雖然進度條不再滾動窗體。親切的問候。克里斯 – IRHM