|
楼主,你的代码并未打开文档,故无法设置页边距。请试试以下代码(请将重要资料打包备份好试验):
- Sub test批量设置页边距()
- 'code by 捷克人
- On Error Resume Next
- Dim fd As FileDialog, p$, doc As Document, n&
- Set fd = Application.FileDialog(msoFileDialogFolderPicker)
- If fd.Show = -1 Then p = fd.SelectedItems(1) Else End
- Set fd = Nothing
- If MsgBox("是否处理文件夹 " & p & " ?", 4 + 48) = vbNo Then End
- Dim FileNameWithPath As Variant, ListOfFilenamesWithParh As New Collection
- Call FileSearchByHavrda(ListOfFilenamesWithParh, p, "*.doc", True)
- For Each FileNameWithPath In ListOfFilenamesWithParh
- Set doc = Documents.Open(FileName:=FileNameWithPath, Visible:=False)
- With doc
- With .PageSetup
- .TopMargin = CentimetersToPoints(2.7)
- .BottomMargin = CentimetersToPoints(3.5)
- End With
- .Close savechanges:=wdSaveChanges
- End With
- n = n + 1
- Next FileNameWithPath
- If ListOfFilenamesWithParh.Count = 0 Then MsgBox "File not found!"
- MsgBox "处理完毕!共处理 " & n & " 个文档!", 0 + 48
- End Sub
- Sub FileSearchByHavrda(pFoundFiles As Collection, pPath As String, pMask As String, pIncludeSubdirectories As Boolean)
- Dim DirFile As String, CollectionItem As Variant, SubDirCollection As New Collection
- pPath = Trim(pPath)
- If Right(pPath, 1) <> "" Then pPath = pPath & ""
- DirFile = Dir(pPath & pMask)
- Do While DirFile <> ""
- pFoundFiles.Add pPath & DirFile
- DirFile = Dir
- Loop
- If Not pIncludeSubdirectories Then Exit Sub
- DirFile = Dir(pPath & "*", vbDirectory)
- Do While DirFile <> ""
- If DirFile <> "." And DirFile <> ".." Then If ((GetAttr(pPath & DirFile) And vbDirectory) = 16) Then SubDirCollection.Add pPath & DirFile
- DirFile = Dir
- Loop
- For Each CollectionItem In SubDirCollection
- Call FileSearchByHavrda(pFoundFiles, CStr(CollectionItem), pMask, pIncludeSubdirectories)
- Next
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|