View Single Post
 
Old 04-14-2012, 07:43 AM
tinfanide tinfanide is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: Aug 2011
Posts: 312
tinfanide is on a distinguished road
Default Word VBA: SaveAs2 - An error?

Run-time Error (5487)
word cannot complete the save due to a file permission error

Code:
Dim str1 As String, str2 As String

With ActiveDocument
    .Select
    With Selection
        .Find.ClearFormatting
        .Find.Execute FindText:="The Principal", MatchWholeWord:=True
        .HomeKey
        .MoveDown
        .EndKey Unit:=wdLine
        .MoveLeft Unit:=wdCharacter, Count:=1
        .HomeKey Unit:=wdLine, Extend:=wdExtend
        str1 = Trim(Selection.Range.Text)
    End With
    .Select
    With Selection
        .Find.Execute FindText:="RE: ", MatchWholeWord:=True
        .MoveRight Unit:=wdCharacter, Count:=1
        .EndKey Unit:=wdLine, Extend:=wdExtend
        str2 = Trim(Selection.Range.Text)
    End With
    .SaveAs2 FileName:=ThisDocument.Path & "\" & str1 & " " & str2, FileFormat:=wdFormatDocumentDefault
End With
Please see the attachment.
I don't know why str2 causes the problem to saving the document.
14 April 2012.docx

Many thanks in advance.
Reply With Quote