tranphamhung1999
Thành viên mới
- Tham gia
- 10/7/19
- Bài viết
- 2
- Được thích
- 0
Cho em hỏi tách file word thành các file khác nhau, mỗi file tách ra là 2 trang.
Tách các file ra 1 trang thì e dùng lệnh VBA dưới đây, nhưng giờ muốn tách thành các file 2 trang thì sửa thế nào ạ.
Em cảm ơn!
Sub tách file 1 trang:
Sub TachFile()
Application.ScreenUpdating = False
Dim Doc As Document, Pages As Long
Set Doc = ActiveDocument
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
Selection.HomeKey Unit:=wdStory
Pages = Doc.BuiltInDocumentProperties(wdPropertyPages)
ChangeFileOpenDirectory ActiveDocument.Path
For i = 1 To Pages - 1
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Cut
With Documents.Add
Selection.Paste
Selection.EndKey Unit:=wdStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If AscW(Selection.Text) = 12 Or AscW(Selection.Text) = 13 Or AscW(Selection.Text) = 22 Then Selection.TypeBackspace
.SaveAs VBA.Format(i + , "000") & Left(Doc.Name, InStrRev(Doc.Name, ".") - 1) & ".doc", 0
.Close
End With
Next
Application.ScreenUpdating = True
End Sub
Tách các file ra 1 trang thì e dùng lệnh VBA dưới đây, nhưng giờ muốn tách thành các file 2 trang thì sửa thế nào ạ.
Em cảm ơn!
Sub tách file 1 trang:
Sub TachFile()
Application.ScreenUpdating = False
Dim Doc As Document, Pages As Long
Set Doc = ActiveDocument
Selection.EndKey Unit:=wdStory
Selection.InsertBreak Type:=wdPageBreak
Selection.HomeKey Unit:=wdStory
Pages = Doc.BuiltInDocumentProperties(wdPropertyPages)
ChangeFileOpenDirectory ActiveDocument.Path
For i = 1 To Pages - 1
Selection.GoTo What:=wdGoToPage, Which:=wdGoToNext, Count:=1
Selection.HomeKey Unit:=wdStory, Extend:=wdExtend
Selection.Cut
With Documents.Add
Selection.Paste
Selection.EndKey Unit:=wdStory
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
If AscW(Selection.Text) = 12 Or AscW(Selection.Text) = 13 Or AscW(Selection.Text) = 22 Then Selection.TypeBackspace
.SaveAs VBA.Format(i + , "000") & Left(Doc.Name, InStrRev(Doc.Name, ".") - 1) & ".doc", 0
.Close
End With
Next
Application.ScreenUpdating = True
End Sub