Page 1 of 1

VBA แยกชุดงานที่ต้องการสร้างไฟล์ใหม่แล้วเซฟ

Posted: Fri Dec 27, 2019 5:38 pm
by Beginner
ขอรบกวนหน่อยครับพอดีตอนนี้จะแยกงานเป็นชุด ๆ ตามจำนวนหน้าที่ต้องการ
แต่ตอนนี้ติดที่ว่ามันแยกเฉพาะหน้าปัจจุบันหน้าเดียว
ตัวอย่างคำตอบที่ต้องการคือในไฟล์มีทั้งหมด 15 หน้า
แต่ต้องการแยกเป็นไฟล์ละ 5 หน้าต้องแก้ไขอย่างไรครับ


Code: Select all

Sub splitter()

Dim Counter As Long, Source As Document, Target As Document
Set Source = ActiveDocument
Selection.HomeKey Unit:=wdStory
Pages = Source.BuiltInDocumentProperties(wdPropertyPages)
Counter = 0
While Counter < Pages
    Counter = Counter + 1
    DocName = "Page" & Format(Counter)
    Source.Bookmarks("\Page").Range.Cut
    Set Target = Documents.Add
    Target.Range.Paste
    Target.SaveAs FileName:=DocName
    Target.Close
Wend
End Sub

Re: VBA แยกชุดงานที่ต้องการสร้างไฟล์ใหม่แล้วเซฟ

Posted: Fri Dec 27, 2019 6:39 pm
by snasui
:D ลองดูตัวอย่าง Code ที่นี่ครับ :arrow: Split word document every x pages