V
VBA
Here is a macro which splits document, and there are a file permission error.
So how can I solve this error.
Sub SplitDoc()
Dim rng As Range
Dim c As Long
Dim i As Integer
Dim pavadinimas As String
Dim Show As Boolean
Show = ActiveDocument.ActiveWindow.View.ShowHiddenText
If Not Show Then ActiveDocument.ActiveWindow.View.ShowHiddenText = True
pavadinimas = ActiveDocument.Paragraphs.First.Range.Text
Set rng = ActiveDocument.Range
rng.Collapse wdCollapseStart
Do
c = rng.MoveEndUntil(Chr$(12), wdForward)
If c = 0 Then
rng.End = ActiveDocument.Range.End
Else
If rng.Paragraphs.First.Range.Characters.First = Chr$(12) Then
pavadinimas = Mid$(rng.Paragraphs.First.Range.Text, 2)
Else
pavadinimas = rng.Paragraphs.First.Range.Text
End If
rng.Start = rng.MoveStartUntil(Chr$(13), wdForward)
rng.Copy
Documents.Add.Range.Paste
i = i + 1
ActiveDocument.SaveAs fileName:=pavadinimas
ActiveDocument.Close
rng.MoveEnd wdCharacter, 1
rng.Collapse wdCollapseEnd
End If
Loop Until c = 0
ActiveDocument.ActiveWindow.View.ShowHiddenText = Show
End Sub
So how can I solve this error.
Sub SplitDoc()
Dim rng As Range
Dim c As Long
Dim i As Integer
Dim pavadinimas As String
Dim Show As Boolean
Show = ActiveDocument.ActiveWindow.View.ShowHiddenText
If Not Show Then ActiveDocument.ActiveWindow.View.ShowHiddenText = True
pavadinimas = ActiveDocument.Paragraphs.First.Range.Text
Set rng = ActiveDocument.Range
rng.Collapse wdCollapseStart
Do
c = rng.MoveEndUntil(Chr$(12), wdForward)
If c = 0 Then
rng.End = ActiveDocument.Range.End
Else
If rng.Paragraphs.First.Range.Characters.First = Chr$(12) Then
pavadinimas = Mid$(rng.Paragraphs.First.Range.Text, 2)
Else
pavadinimas = rng.Paragraphs.First.Range.Text
End If
rng.Start = rng.MoveStartUntil(Chr$(13), wdForward)
rng.Copy
Documents.Add.Range.Paste
i = i + 1
ActiveDocument.SaveAs fileName:=pavadinimas
ActiveDocument.Close
rng.MoveEnd wdCharacter, 1
rng.Collapse wdCollapseEnd
End If
Loop Until c = 0
ActiveDocument.ActiveWindow.View.ShowHiddenText = Show
End Sub