문제

Excel에서 데이터베이스 보고서 생성기를 만들었습니다.프로그램이 실행될 때 상태 정보를 표시하는 대화 상자를 만들려고 합니다.

보고서를 생성할 때 대화 상자가 나타나더라도 표시되는 정보를 새로 고치거나 업데이트할 수 없습니다.대부분의 경우 대화 상자는 부분적으로만 나타납니다..repaint 방법을 사용해 보았지만 여전히 동일한 결과를 얻습니다.보고서가 생성된 후에만 전체 대화 상자가 표시됩니다.

도움이 되었습니까?

해결책

아래 코드는 Excel(XP 이상) 내에서 작업을 수행할 때 잘 작동합니다.

예를 들어 데이터베이스에 연결하고 데이터를 검색하는 등 Excel 외부에서 발생하는 작업의 경우 이 기능은 작업 전후에 대화 상자를 표시할 수 있는 기회입니다(예: "데이터 가져오기", "데이터를 얻었습니다")

라는 양식을 만듭니다. "frm상태", 라는 양식에 레이블을 붙입니다. "라벨1".

양식 속성 설정 'ShowModal' = 거짓, 이를 통해 양식이 표시되는 동안 코드를 실행할 수 있습니다.

Sub ShowForm_DoSomething()

    Load frmStatus
    frmStatus.Label1.Caption = "Starting"
    frmStatus.Show
    frmStatus.Repaint
'Load the form and set text

    frmStatus.Label1.Caption = "Doing something"
    frmStatus.Repaint

'code here to perform an action

    frmStatus.Label1.Caption = "Doing something else"
    frmStatus.Repaint

'code here to perform an action

    frmStatus.Label1.Caption = "Finished"
    frmStatus.Repaint
    Application.Wait (Now + TimeValue("0:00:01"))
    frmStatus.Hide
    Unload frmStatus
'hide and unload the form

End Sub

다른 팁

추가해 보세요 Do이벤트 루프를 호출하십시오.그러면 양식이 다시 그려지고 다른 요청을 수락할 수 있게 됩니다.

나는 과거에 개발한 유사한 응용 프로그램에 대한 진행 정보를 표시하기 위해 Excel의 자체 상태 표시줄(창 왼쪽 하단)을 사용했습니다.

진행 상황에 대한 텍스트 업데이트를 표시하고 업데이트 대화 상자가 전혀 필요하지 않은 경우 매우 잘 작동합니다.

좋아요 @JonnyGold, 여기 제가 사용한 종류의 예가 있습니다...

Sub StatusBarExample()
    Application.ScreenUpdating = False 
    ' turns off screen updating
    Application.DisplayStatusBar = True 
    ' makes sure that the statusbar is visible
    Application.StatusBar = "Please wait while performing task 1..."
    ' add some code for task 1 that replaces the next sentence
    Application.Wait Now + TimeValue("00:00:02")
    Application.StatusBar = "Please wait while performing task 2..."
    ' add some code for task 2 that replaces the next sentence
    Application.Wait Now + TimeValue("00:00:02")
    Application.StatusBar = False 
    ' gives control of the statusbar back to the programme
End Sub

도움이 되었기를 바랍니다!

통합 문서에 빈 시트를 삽입하여 시트의 이름을 바꿉니다."정보"

Sheets("information").Select
Range("C3").Select
ActiveCell.FormulaR1C1 = "Updating Records"
Application.ScreenUpdating = False
Application.Wait Now + TimeValue("00:00:02")

매크로 계속

Sheets("information").Select
Range("C3").Select
Application.ScreenUpdating = True
ActiveCell.FormulaR1C1 = "Preparing Information"
Application.ScreenUpdating = False
Application.Wait Now + TimeValue("00:00:02")

매크로 계속

등 또는 새 시트를 삽입하는 대신 기존 시트 어딘가에 빈 셀을 선택하십시오.

Range("C3").Select
ActiveCell.FormulaR1C1 = "Updating Records"
Application.ScreenUpdating = False
Application.Wait Now + TimeValue("00:00:02")

대화 상자도 동일한 UI 스레드에서 실행됩니다.그래서 다시 칠하기에는 너무 바빠요.VBA에 우수한 멀티스레딩 기능이 있는지 확실하지 않습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top