VBA/Excel/Access/Word/Word/Documents
Содержание
- 1 Changes all bold formatting in the open document named Example.doc to italic formatting.
- 2 Check the current document count
- 3 Loop through the Documents
- 4 To maximize, minimize, or "restore" a window, set its WindowState property to wdWindowStateMaximize, wdWindowStateMinimize, or wdWindowStateNormal, respectively
Changes all bold formatting in the open document named Example.doc to italic formatting.
<source lang="vb">
Sub change()
With Documents("Example.doc").Content.Find .ClearFormatting .Font.Bold = True With .Replacement .ClearFormatting .Font.Bold = False .Font.Italic = True End With .Execute FindText:="A", ReplaceWith:="B", _ Format:=True, replace:=wdReplaceAll End With
End Sub
</source>
Check the current document count
<source lang="vb">
Sub box()
If Documents.Count = 0 Then Proceed = MsgBox("no document.Please open a document.", vbOKCancel + vbExclamation, "Format Report") If Proceed = vbOK Then Dialogs(wdDialogFileOpen).Show If Documents.Count = 0 Then End Else End End If End If
End Sub
</source>
Loop through the Documents
<source lang="vb">
Sub forEach()
Dim Doc As Document For Each Doc In Documents Doc.Close SaveChanges:=wdSaveChanges Next
End Sub
</source>
To maximize, minimize, or "restore" a window, set its WindowState property to wdWindowStateMaximize, wdWindowStateMinimize, or wdWindowStateNormal, respectively
<source lang="vb">
Sub max()
With Documents("Example.doc").Windows(1) If .WindowState = wdWindowStateMinimize Then _ .WindowState = wdWindowStateMaximize End With
End Sub
</source>