From: VBA VBA on 16 Jun 2008 04:11 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
From: Doug Robbins - Word MVP on 16 Jun 2008 04:33 I would rewrite the code as follows: Sub SplitDoc() Dim rng As Range Dim c As Long Dim i As Integer Dim pavadinimas As String Dim Show As Boolean Dim Source as Document, Target as Document Set Source = ActiveDocument Show = Source.ActiveWindow.View.ShowHiddenText If Not Show Then Source.ActiveWindow.View.ShowHiddenText = True pavadinimas = Source.Paragraphs.First.Range.Text Set rng = Source.Range rng.Collapse wdCollapseStart Do c = rng.MoveEndUntil(Chr$(12), wdForward) If c = 0 Then rng.End = Source.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 Set Target = Documents.Add Target.Range.Paste i = i + 1 Target.SaveAs fileName:=pavadinimas Target.Close rng.MoveEnd wdCharacter, 1 rng.Collapse wdCollapseEnd End If Loop Until c = 0 Source.ActiveWindow.View.ShowHiddenText = Show End Sub Your problem could be the system losing track of the ActiveDocument, which the above modification will prevent. If not, what line of code is highlighted if you click on Debug. -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "VBA" <VBA @discussions.microsoft.com> wrote in message news:E93BF4FB-C233-4F30-BAF6-124C46465D4A(a)microsoft.com... > 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 > > > >
From: VBA on 16 Jun 2008 06:07 When I click on Debug the line is highlighted Targer.SaveAs fileName:=pavadinimas Arnoldas Rope "Doug Robbins - Word MVP" wrote: > I would rewrite the code as follows: > > Sub SplitDoc() > > Dim rng As Range > Dim c As Long > Dim i As Integer > Dim pavadinimas As String > Dim Show As Boolean > Dim Source as Document, Target as Document > > Set Source = ActiveDocument > > Show = Source.ActiveWindow.View.ShowHiddenText > If Not Show Then Source.ActiveWindow.View.ShowHiddenText = True > pavadinimas = Source.Paragraphs.First.Range.Text > > Set rng = Source.Range > rng.Collapse wdCollapseStart > Do > c = rng.MoveEndUntil(Chr$(12), wdForward) > If c = 0 Then > rng.End = Source.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 > Set Target = Documents.Add > Target.Range.Paste > i = i + 1 > Target.SaveAs fileName:=pavadinimas > Target.Close > rng.MoveEnd wdCharacter, 1 > rng.Collapse wdCollapseEnd > End If > Loop Until c = 0 > Source.ActiveWindow.View.ShowHiddenText = Show > End Sub > > Your problem could be the system losing track of the ActiveDocument, which > the above modification will prevent. > > If not, what line of code is highlighted if you click on Debug. > > > -- > Hope this helps. > > Please reply to the newsgroup unless you wish to avail yourself of my > services on a paid consulting basis. > > Doug Robbins - Word MVP
From: Doug Robbins - Word MVP on 16 Jun 2008 07:20 And what does pavadinimas contain at that point? -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "VBA" <VBA(a)discussions.microsoft.com> wrote in message news:D35E8404-578F-4A1F-8D62-E458554B2332(a)microsoft.com... > When I click on Debug the line is highlighted Targer.SaveAs > fileName:=pavadinimas > > > Arnoldas Rope > > > > "Doug Robbins - Word MVP" wrote: > >> I would rewrite the code as follows: >> >> Sub SplitDoc() >> >> Dim rng As Range >> Dim c As Long >> Dim i As Integer >> Dim pavadinimas As String >> Dim Show As Boolean >> Dim Source as Document, Target as Document >> >> Set Source = ActiveDocument >> >> Show = Source.ActiveWindow.View.ShowHiddenText >> If Not Show Then Source.ActiveWindow.View.ShowHiddenText = True >> pavadinimas = Source.Paragraphs.First.Range.Text >> >> Set rng = Source.Range >> rng.Collapse wdCollapseStart >> Do >> c = rng.MoveEndUntil(Chr$(12), wdForward) >> If c = 0 Then >> rng.End = Source.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 >> Set Target = Documents.Add >> Target.Range.Paste >> i = i + 1 >> Target.SaveAs fileName:=pavadinimas >> Target.Close >> rng.MoveEnd wdCharacter, 1 >> rng.Collapse wdCollapseEnd >> End If >> Loop Until c = 0 >> Source.ActiveWindow.View.ShowHiddenText = Show >> End Sub >> >> Your problem could be the system losing track of the ActiveDocument, >> which >> the above modification will prevent. >> >> If not, what line of code is highlighted if you click on Debug. >> >> >> -- >> Hope this helps. >> >> Please reply to the newsgroup unless you wish to avail yourself of my >> services on a paid consulting basis. >> >> Doug Robbins - Word MVP
From: VBA on 16 Jun 2008 07:43 Pavadinimas contains first line after page break, I want that don't copy to pavadinimas enter symbol.so could you tell me what i need to change in macro? "Doug Robbins - Word MVP" wrote: > And what does pavadinimas contain at that point? > > -- > Hope this helps. > > Please reply to the newsgroup unless you wish to avail yourself of my > services on a paid consulting basis. > > Doug Robbins - Word MVP > > "VBA" <VBA(a)discussions.microsoft.com> wrote in message > news:D35E8404-578F-4A1F-8D62-E458554B2332(a)microsoft.com... > > When I click on Debug the line is highlighted Targer.SaveAs > > fileName:=pavadinimas > > > > > > Arnoldas Rope > > > > > > > > "Doug Robbins - Word MVP" wrote: > > > >> I would rewrite the code as follows: > >> > >> Sub SplitDoc() > >> > >> Dim rng As Range > >> Dim c As Long > >> Dim i As Integer > >> Dim pavadinimas As String > >> Dim Show As Boolean > >> Dim Source as Document, Target as Document > >> > >> Set Source = ActiveDocument > >> > >> Show = Source.ActiveWindow.View.ShowHiddenText > >> If Not Show Then Source.ActiveWindow.View.ShowHiddenText = True > >> pavadinimas = Source.Paragraphs.First.Range.Text > >> > >> Set rng = Source.Range > >> rng.Collapse wdCollapseStart > >> Do > >> c = rng.MoveEndUntil(Chr$(12), wdForward) > >> If c = 0 Then > >> rng.End = Source.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 > >> Set Target = Documents.Add > >> Target.Range.Paste > >> i = i + 1 > >> Target.SaveAs fileName:=pavadinimas > >> Target.Close > >> rng.MoveEnd wdCharacter, 1 > >> rng.Collapse wdCollapseEnd > >> End If > >> Loop Until c = 0 > >> Source.ActiveWindow.View.ShowHiddenText = Show > >> End Sub > >> > >> Your problem could be the system losing track of the ActiveDocument, > >> which > >> the above modification will prevent. > >> > >> If not, what line of code is highlighted if you click on Debug. > >> > >> > >> -- > >> Hope this helps. > >> > >> Please reply to the newsgroup unless you wish to avail yourself of my > >> services on a paid consulting basis. > >> > >> Doug Robbins - Word MVP > > >
|
Next
|
Last
Pages: 1 2 Prev: cannot open macro storage error Next: Select a network printer from the command line |