2008-09-09 12 views
3

Excelでデータベースレポートジェネレータを作成しました。プログラムの実行中にステータス情報を表示するダイアログボックスを作成しようとしています。Excelでステータスダイアログボックスを作成するには

レポートを生成すると、ダイアログボックスが表示されても表示される情報を更新/更新できません。ほとんどの場合、ダイアログボックスは部分的にしか表示されません。私は.repaintメソッドを使ってみましたが、私はまだ同じ結果を得ています。レポートが生成された後、完全なダイアログボックスが表示されます。

答えて

2

Excel(XP以降)内でアクションを実行する場合、以下のコードはうまく機能します。エクセル外に場所を取るアクションのために

、例えばデータベースに接続し、データを取得、これは提供しています最高の「データの取得」など(アクションの前と後にダイアログを表示するための機会である、「ゴット・データ」

は、"frmStatus"と呼ばれるフォームを作成し、フォーム上のラベルを置く"のLabel1"と呼ばれます。

フォームプロパティを'ShowModal' = falseに設定すると、フォームが表示されている間にコードを実行できます。

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 
0

ダイアログボックスも同じUIスレッドで実行されています。それで、それはあまりにも忙しすぎて自分自身を再描きません。 VBAに優れたマルチスレッド機能があるかどうかは不明です。

4

私は過去に開発した同様のアプリケーションの進捗情報を表示するために、Excelの独自のステータスバー(ウィンドウの左下)を使用しました。

進捗状況のテキスト更新を表示したいだけで、更新ダイアログが必要ない場合は非常に効果的です。

[OK]を@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 

・ホープ、このことができます!

+0

ありがとうございました。ありがとうございました。 – JonnyGold

6

DoEventsをループに追加してみてください。それはフォームが他の要求を受け入れるために&を再ペイントするためのフォームを許可する必要があります。

2

は、シートなどの名前を変更し、あなたのワークブックに白紙を挿入します。 "情報"

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") 

その他

関連する問題