-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewMacros.bas
87 lines (79 loc) · 2.36 KB
/
NewMacros.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Attribute VB_Name = "NewMacros"
Sub AutoExec()
' Wait until a document opens.
Application.OnTime Now, "AutoNew"
End Sub
Sub AutoOpen()
If DocumentIsText() Then
AutoNew
End If
End Sub
Sub AutoNew()
If Windows.Count = 0 Then
Exit Sub
End If
' Ensure that the draft font isn't used
' (e.g., if you say "draft view" by accident)
With Dialogs(wdDialogToolsOptionsView)
.DraftFont = DocumentIsText()
.Execute
End With
' Draft view is wdNormalView.
If ActiveWindow.View.Type = wdPrintView Then
ActiveWindow.View.Type = wdNormalView
End If
' If window isn't maximized, ribbon doesn't collapse fully.
ActiveWindow.WindowState = wdWindowStateMaximize
' Use full screen mode since we can control it from VBA.
ActiveWindow.View.FullScreen = True
' Wrap to window and hide the horizontal scroll bar.
ActiveWindow.View.WrapToWindow = True
ActiveWindow.DisplayHorizontalScrollBar = False
End Sub
Public Sub SimulateSave()
If ActiveDocument.Path = vbNullString Then
Application.Dialogs(wdDialogFileSaveAs).Show
Else
ActiveDocument.Save
End If
End Sub
Public Sub SaveWithoutPrompting()
If ActiveDocument.Saved = True Then
Exit Sub
End If
If DocumentIsText() Then
Application.DisplayAlerts = wdAlertsNone
SimulateSave
Application.DisplayAlerts = wdAlertsAll
Else
SimulateSave
End If
End Sub
Public Function DocumentIsText()
Select Case ActiveDocument.SaveFormat
Case WdSaveFormat.wdFormatText, _
WdSaveFormat.wdFormatTextLineBreaks, _
WdSaveFormat.wdFormatDOSText, _
WdSaveFormat.wdFormatDOSTextLineBreaks, _
WdSaveFormat.wdFormatEncodedText, _
WdSaveFormat.wdFormatUnicodeText
DocumentIsText = True
Case Else
DocumentIsText = False
End Select
End Function
Sub FindPlaceholder(Forward As Boolean)
With Selection.Find
.ClearFormatting
.Wrap = wdFindContinue
.MatchWholeWord = False
.Forward = Forward
.Execute FindText:="***"
End With
End Sub
Public Sub FindNextPlaceholder()
FindPlaceholder (True)
End Sub
Public Sub FindPreviousPlaceholder()
FindPlaceholder (False)
End Sub