Microsoft WORDを開き、表示、マクロ、マクロの表示、新しいマクロを作成する
Sub a()
Dim myDialogs As FileDialogs, oDoc As Documents, oSecs As Sections
Dim oFile As Variant, myRange As Range
On Error Resume Next
フォルダ選択ダイアログボックスを定義する
Set myDialogue=Application.FileDialog(msoFileDialogFilePicker)
With myDialogs
. .Filters.Clear ‘ファイルフィルターのすべての項目をクリア
. .Filters.Add “すべてのWordファイル”, “*.doc, *.docx”, 1 ‘すべてのWordファイルにフィルターを追加
. .AllowMultiSelect=True ‘複数選択を許可
If Show=-1 Then ‘OK
For Each oFile In SelectedItems ’選択されたすべての項目をループ
Set oDoc=Word.Documents.Open(FileName:=oFile, Visible:=False)
For Each oSec In oDoc.Sections 'ドキュメント内のセクションをループ
Set myRange=oSec.Headers(wdHeaderFooterPrimary).Range
MyRange.Delete ‘ヘッダーの内容を削除
MyRange.Text=”www.jincan.net”
MyRange.ParagraphFormat.Alignment=wdAlignParagraphCenter ‘テキストを中央揃え
MyRange.ParagraphFormat.Borders(wdBorderBottom).LineStyle=wdLineStyleNone ‘段落の下罫線なし
With myRange Font
End With
Set myRange=oSec Footers (wdHeaderFooterPrimary) Range
MyRange Delete ‘Delete the content in the footer
MyRange Collapse wdCollapseEnd
MyRange InsertAfter Page Number
MyRange Fields Add Range:=myRange, Type:=wdFieldEmpty, Text:=”PAGE”, PreserveFormatting:=True
MyRange ParagraphFormat Alignment=wdAlignParagraphCenter ‘Center page numbers
Next
ODoc Close True
Next
End If
End With
End Sub
ワッツアップ+8613603031172