0

Hello! I wonder if someone can help me. I'm trying to create a Macro that would copy a line of text from one Word doc into a specific position of another Word doc, and then use the content of the clipboard as the Filename. From recording various Macros and researching on the internet, I've come to the Macro as below.

However, it shows an error 5487 - Word cannot complete the Save due to a file permission error. Although this bit had been previously reported on one of the forums as a working one. I'd be most greatful of comeone could advise.

Also, this is actually not an ideal solution for me as it requires having the target file Report Header to be open. I'd also like to make Word open it as a part of the Macro but failed to make this happen.

Thanks in anticipation,
Maria

Sub Macro3()

Selection.HomeKey Unit:=wdStory
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Cut
Windows("Report Header.doc").Activate
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.EndKey Unit:=wdLine
Selection.PasteAndFormat (wdPasteDefault)

ClipboardText = Selection
ActiveDocument.SaveAs FileName:=ClipboardText & ".doc", FileFormat:=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
ActiveWindow.Close
End Sub

1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by maria_college
0

I realised that the offending symbol was the paragraph mark in the end of my text string.
On the internet they suggested the following solution

If InStr(Docname, vbCr) <> 0 Then
Docname = Trim(Left(Docname, InStr(Docname, vbCr) - 1))
End If

I've included the above jin the ned of my macro:

ActiveDocument.SaveAs FileName:="C:\Marias Documents\College\Word Reports Old Style\ClipboardText.doc", FileFormat:=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False

If InStr(Docname, vbCr) <> 0 Then
Docname = Trim(Left(Docname, InStr(Docname, vbCr) - 1))
End If
ActiveWindow.Close
End Sub

Now running it leads to error 5941, the requested member of the collection does not exist. I'd ancountered this before and here it is again! What's wrong?

Thanks in advance
Maria

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.