
Sub BreakOnPage ()
Application.Browser.Target = wdBrowsePage
'ciclo dalla prima all'ultima pagina
Per i = 1 a ActiveDocument.BuiltInDocumentProperties ("Numero di pagine")
'seleziono e copio il testo negli appunti
ActiveDocument.Bookmarks (" page"). Range.Copy
'creo un nuovo file e incollo gli appunti del foglio
Documents.Add
Selection.Paste
Selection.TypeBackspace
'imposto il percorso di salvataggio del file creato
ChangeFileOpenDirectory "C:Desktopcartella"
DocNum DocNum = + 1
'salvo il file con nome: esempio "foglio_1", "foglio_2" ecc...
ActiveDocument.SaveAs FileName: = "foglio_" & DocNum & ". Doc"
ActiveDocument.Close
Application.Browser.Next
Next i
SaveChanges ActiveDocument.Close: = wdDoNotSaveChanges
End Sub |
Sub BreakOnPage()
filetoopen = Application.GetOpenFilename("DOC Files (*.DOC), *.DOC", , "Selezionare il percorso ed il file DOC ", "Apri", False)
If filetoopen = False Then Exit Sub
Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Open filetoopen
' Application.Browser.Target = wdBrowsePage
For i = 1 To ActiveDocument.BuiltinDocumentProperties("NUMERO DI PAGINE")
'Select and copy the text to the clipboard.
ActiveDocument.Bookmarks("page").Range.Copy
' Open new document to paste the content of the clipboard into.
Documents.Add
Selection.Paste
Selection.TypeBackspace
'ChangeFileOpenDirectory "C:" ..... qui ho messo l'apice perche' non funziona
DocNum = DocNum + 1
ActiveDocument.SaveAs Filename:="C:" & "test_" & DocNum & ".doc"
ActiveDocument.Close
' Move the selection to the next page in the document.
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub |
Sub BreakOnPage()
filetoopen = Application.GetOpenFilename("DOC Files (*.DOC), *.DOC", , "Selezionare il percorso ed il file DOC ", "Apri", False)
If filetoopen = False Then Exit Sub
Set wdApp = CreateObject("Word.Application")
wdApp.Documents.Open filetoopen
For i = 1 To ActiveDocument.BuiltinDocumentProperties("Number of Pages")
ActiveDocument.Bookmarks("page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
DocNum = DocNum + 1
ActiveDocument.SaveAs Filename:="C:" & "test_" & DocNum & ".doc"
ActiveDocument.Close
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
|
Sub BreakOnPage()
Application.Browser.Target = wdBrowsePage
For i = 1 To ActiveDocument.BuiltInDocumentProperties("Number of Pages")
ActiveDocument.Bookmarks("page").Range.Copy
Documents.Add
Selection.Paste
Selection.TypeBackspace
ChangeFileOpenDirectory "C:"
DocNum = DocNum + 1
ActiveDocument.SaveAs FileName:="test_" & DocNum & ".doc"
ActiveDocument.Close
Application.Browser.Next
Next i
ActiveDocument.Close savechanges:=wdDoNotSaveChanges
End Sub
|
Option Explicit
Sub dividi_file_word()
Dim filetoopen, i As Integer
Dim wrdApp As Word.Application
Dim pagina As Object
Dim nome As String, percorso As String
Dim pag As Integer, inizio As Long, fine As Long
Dim doc_a As Document, doc_da As Document
filetoopen = Application.GetOpenFilename("DOC Files (*.DOC), *.DOC", , "Selezionare il percorso ed il file DOC ", "Apri", False)
If filetoopen = False Then Exit Sub
Set wrdApp = CreateObject("Word.Application")
With wrdApp
.Documents.Open filetoopen
.Visible = True
.Activate
Set doc_da = .ActiveDocument
'nome che assumeranno i singoli file
nome = "Pagina_"
'percorso di salvataggio (cartella dove si trova il file da dividere)
percorso = .ActiveDocument.Path
Set pagina = doc_da.Range(0, 0)
inizio = pagina.Start
fine = pagina.GoToNext(wdGoToPage).Start
While inizio <> fine
pag = pag + 1
pagina.SetRange inizio, fine
pagina.Copy
Set doc_a = .Documents.Add
doc_a.Range.Paste
doc_a.SaveAs percorso & "" & nome & "_" & pag & ".doc"
doc_a.Close
pagina.SetRange fine, fine
inizio = fine
fine = pagina.GoToNext(wdGoToPage).Start
Wend
pagina.EndOf wdStory, wdExtend
pagina.Copy
Set doc_a = .Documents.Add
doc_a.Range.Paste
doc_a.SaveAs percorso & "" & nome & "_" & pag + 1 & ".doc"
doc_a.Close
.Quit
End With
Set doc_a = Nothing
Set doc_da = Nothing
Set wrdApp = Nothing
End Sub
|
