huuthang_bd
Chuyên gia GPE

Bạn thử Macro này thử xem. Sử dụng cho file nào cũng được, 1 trang được tách ra làm 1 file.Em đã download file test và làm như hướng dẫn để chia mỗi trang trong file word thành 1 file, nhưng khi thực hiện (Alt+F8) thì nó cứ báo lỗi : Fname = "File_" & VBA.Format(i, "000") & "_" & Mid(Selection.Text, 10, Len(Selection.Text) - 11) & ".doc"
Các bác giúp em làm sao để chia mỗi trang thành 1 file, mà tên mỗi file có tên nhân viên trong mỗi trang.
Thanks các bác nhiều !
Mã:
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 Left(Doc.Name, InStrRev(Doc.Name, ".") - 1) & "_" & VBA.Format(i, "000") & ".doc", 0
.Close
End With
Next
Application.ScreenUpdating = True
End Sub