Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File Name Runtime 5487 "Permission" Error

1,279 views
Skip to first unread message

Utsekaj

unread,
Jun 22, 2009, 8:14:02 AM6/22/09
to

I'm am trying to use the following macro to extract text from an open file
and save it with the first line as the file name.

However the following Dialogue comes up

"
Runtime Error '5487'

Word cannot complete the save due to a file permissions error:
"
Can anyone tell me why this is happening and how I may fix it?

Sub CopyFormat()
'
' CopyFormat macro
'
'

Selection.Copy

Documents.Add Template:= _
"C:\Documents and Settings\user\My
Documents\Malaysia\Penan\Song.dotx", _
NewTemplate:=False, DocumentType:=0

Selection.PasteAndFormat Type:=wdFormatPlainText


Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
Selection.Style = ActiveDocument.Styles("Song Title")
Dim Title As String
Title = "C:\Documents and Settings\user\My
Documents\Malaysia\Penan\Songs\" & Selection.Text & ".docx"


Selection.EndKey Unit:=wdStory

Selection.Style = ActiveDocument.Styles("Normal")
With ActiveDocument.Styles("Normal").Font
.Name = "Times New Roman"
.Size = 14
.Bold = False
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorAutomatic
.Engrave = False
.Superscript = False
.Subscript = False
.Scaling = 100
.Kerning = 0
.Animation = wdAnimationNone
End With
With ActiveDocument.Styles("Normal")
.AutomaticallyUpdate = False
.BaseStyle = ""
.NextParagraphStyle = "Normal"
End With

ActiveDocument.SaveAs Title

ActiveWindow.Close
End Sub

Utsekaj

unread,
Jun 23, 2009, 1:52:02 AM6/23/09
to

Utsekaj Wrote


>
>
> Selection.HomeKey Unit:=wdStory
> Selection.MoveDown Unit:=wdParagraph, Count:=1, Extend:=wdExtend
> Selection.Style = ActiveDocument.Styles("Song Title")
> Dim Title As String
> Title = "C:\Documents and Settings\user\My
> Documents\Malaysia\Penan\Songs\" & Selection.Text & ".docx"
>


I found a solution under another thread. The selection contains a Paragraph
character. So inserting this code from Russ found in this thread
"File Permission Error Runtime 5487 - Splitting Mail Merge Document in
microsoft.public.word.vba.general"

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

Using that If cleans the Title and allows it to save.

Substitute Title, following its first definition.

0 new messages