'開かれたDocumentのコレクション
Public gOpenDocs As New Collection
'「読みやすさよりもレイアウトを優先して、文字の配置を最適化する」 の値を保管
Public gblnUserVal_PrecisePositioning As Boolean
'--------*---------*---------*---------*---------*---------*---------*---------
'Applicationイベントハンドラ
Public WithEvents AppEvent As Word.Application
'--------*---------*---------*---------*---------*---------*---------*---------
'レイアウト優先のCheck状態 設定と復元のための処理(New時)
Private Sub Document_New()
'「読みやすさよりもレイアウトを優先して、文字の配置を最適化する」 の値を保管
If gOpenDocs.Count = 0 Then
gblnUserVal_PrecisePositioning = Options.PrecisePositioning
End If
'設定値戻しの準備
If Not gblnUserVal_PrecisePositioning Then
Call gOpenDocs.Add(Me)
Set ThisDocument.AppEvent = Word.Application
'レイアウト優先
Options.PrecisePositioning = True
End If
End Sub
'--------*---------*---------*---------*---------*---------*---------*---------
'レイアウト優先のCheck状態 設定と復元のための処理(Open時)
Private Sub Document_Open()
Call Document_New
End Sub
'--------*---------*---------*---------*---------*---------*---------*---------
'レイアウト優先のCheck状態 設定と復元のための処理(New時)
Private Sub AppEvent_DocumentBeforeClose( _
ByVal doc As Document, Cancel As Boolean)
Dim i As Integer
'ckecked使用時は通常の処理
If gblnUserVal_PrecisePositioning Then Exit Sub
'Open/CloseでコレクションにAdd/Removeして管理。最終docなら設定値を戻す
For i = 1 To gOpenDocs.Count
If gOpenDocs(i) Is doc Then
Call gOpenDocs.Remove(i)
If gOpenDocs.Count = 0 Then
Options.PrecisePositioning = False
End If
Exit For
End If
Next
'Unckecked使用時は、変更して未保存でも破棄される仕様
If doc.Path = "" Then doc.SaveAs "C:\tmp\tmp.doc"
doc.Saved = True
End Sub
'--------*---------*---------*---------*---------*---------*---------*---------
'レイアウト優先のCheck状態 設定と復元のための処理(Open時)
Private Sub Document_Close()
Call AppEvent_DocumentBeforeClose(ThisDocument, False)
End Sub
PR
Calendar
Keyword Search