2013-11-23 1 views
3

다음 양식은 내 양식에서 실행 중입니다. 하위가 실행될 때까지 시간이 걸릴 수 있으므로 커서를 모래 시계로 변경하고 코드가 실행되는 동안 Please Wait 메시지를 표시하려고합니다. 여기 내 절차 :모래 시계 표시 또는 하위 실행 중 잠시 기다려주십시오.

Public Sub GoToSheets(sheetName As String) 

'This sub is used to open the workbook on the selected sheet. 
'This checks to see if Excel workbook is opened, if not it 
'opens Excel, the workbook and then the selected sheet. If the workbook is 
'opened, it goes to the selected sheet. 

'@param sheetName, sheet to be displayed 

Try 
    'get an existing excel.application object 
    xlApp = CType(GetObject(, "Excel.Application"), Application) 
Catch ex As Exception 
    'no existing excel.application object - create a new one 

    xlApp = New Excel.Application 

End Try 

Dim xlWBName As String = "2011.1004.Compensation Template" 
Dim xlBookPath As String = Path.Combine(Directory.GetCurrentDirectory()) 

xlApp.Visible = True 

Try 
    'get the opened workbook 
    xlBook = xlApp.Workbooks(xlWBName & ".xlsx") 
Catch ex As Exception 
    'open it 
    xlBook = xlApp.Workbooks.Open(xlBookPath & "\" & xlWBName & ".xlsx") 
End Try 

Try 

    xlSheet = CType(CType(xlBook.Sheets("summarySheet"), Excel.Worksheet), Excel.Worksheet) 
    Dim strChckRange As String = xlSheet.Range("A2").Value 

    If strChckRange Is Nothing Then 

     Dim frmClientInfo As New frmClientInformation 
     frmClientInfo.ShowDialog() 

     closeXLApp() 

    Else 


     xlSheet = CType(CType(xlBook.Sheets(sheetName), Excel.Worksheet), Excel.Worksheet) 


     'close the navigation instance on the welcome page 
     frmNavigation.Close() 
     'activate requested sheet 
     xlSheet.Activate() 
     'display as dashboard 
     DashboardView() 

     System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) 

     GC.Collect() 
     GC.WaitForPendingFinalizers() 
     GC.Collect() 
     GC.WaitForPendingFinalizers() 

     frmWelcomePage.Hide() 
     chkForm() 

    End If 

Catch ex As Exception 

End Try 

최종 하위

나는 비주얼 베이직에 대한 지금까지 아무것도이에 대한 몇 가지 연구를하지만했다.

답변

3

Please Wait...이라는 메시지가 표시된 PleaseWaitForm을 만든 다음 모드가없는 것으로 표시된 양식을 사용하고 모래 시계로 커서를 변경하고 Excel 작업을 수행 한 다음 커서를 기본값으로 다시 변경하고 PleaseWaitForm을 숨기는 것이 좋습니다.

Dim pleaseWait As New PleaseWaitForm 
pleaseWait.Show() 

' Set cursor as hourglass 
Cursor.Current = Cursors.WaitCursor 

Application.DoEvents 

' Execute your GoToSheets method here 

' Set cursor as default arrow 
Cursor.Current = Cursors.Default 

' Hide the please wait form 
pleaseWait.Hide() 
관련 문제