Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

File Permission Error Runtime 5487 - Splitting Mail Merge Document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Wendy - 06 Oct 2007 20:32 GMT
Hi,
I've got this code and I'm getting the above error when I run it:

Sub splitter()
'
' Splitter Macro
'
'

Dim Letters As Integer, Counter As Integer
Letters = ActiveDocument.Sections.Count
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters

ActiveDocument.Sections.First.Range.Cut
Documents.Add
Selection.Paste
Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
Docname = Trim(Selection.Text)
ActiveDocument.Sections(2).PageSetup.SectionStart = wdSectionContinuous
ActiveDocument.SaveAs FileName:="D:\" & Docname
ActiveWindow.Close
Counter = Counter + 1
Wend

End Sub

The error occurs when trying to save each individual file - if I execute the
save manually with the clipboard contents at the point of breaking, the file
saves okay. Why would it not work in this macro context? Any clues? I've got
a 200 page document that needs splitting by tomorrow.

Thanks guys

Woo
Russ - 07 Oct 2007 00:31 GMT
Howdy Woo,
I think it is breaking where you amended Doug's code to get a filename.
See in message below response.

> Hi,
> I've got this code and I'm getting the above error when I run it:
[quoted text clipped - 17 lines]
> Selection.EndKey Unit:=wdLine, Extend:=wdExtend
> Selection.Copy
Selection.Copy was just for testing, right?

> Docname = Trim(Selection.Text)
Docname might have a paragraph mark in it?
Msgbox "zz" & Docname & "zz"

You could use:
If InStr(Docname, vbCR) <> 0 then
   Docname = Trim(Left(Docname, InStr(Docname, vbCR) - 1))
End If

Remember docname must adhere to file naming syntax (punctuation may confuse
Windows OS).

> ActiveDocument.Sections(2).PageSetup.SectionStart = wdSectionContinuous
> ActiveDocument.SaveAs FileName:="D:\" & Docname
[quoted text clipped - 12 lines]
>
> Woo

Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.