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 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.