A
Anthony Dowd
Hi
I'm trying to create a macro that selects a given line of text in a word
document, then saves the document with this text as the file name.
The code below produces the following error:
Run Time Error 5487: Word can not complete the save due to a file permission
error.
******************************************************
Sub Macro1()
Dim stDocName As String
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=11
Selection.MoveRight Unit:=wdCharacter, Count:=12
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
stDocName = Selection
ActiveDocument.SaveAs FileName:= _
"Operation" & stDocName & ".doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
End Sub
****************************************************
I have tried a variation of the file name line above ("Operation" &
Selection.Paste & ".doc", FileFormat:= _) to paste the selected text as the
file name but got the following error:
"Compile Error: Expected Function or variable"
but I'm probably closer to the mark with the line of code as it is in the
above block of code.
Any suggestions?
Anthony
I'm trying to create a macro that selects a given line of text in a word
document, then saves the document with this text as the file name.
The code below produces the following error:
Run Time Error 5487: Word can not complete the save due to a file permission
error.
******************************************************
Sub Macro1()
Dim stDocName As String
Selection.HomeKey Unit:=wdStory
Selection.MoveDown Unit:=wdLine, Count:=11
Selection.MoveRight Unit:=wdCharacter, Count:=12
Selection.EndKey Unit:=wdLine, Extend:=wdExtend
Selection.Copy
stDocName = Selection
ActiveDocument.SaveAs FileName:= _
"Operation" & stDocName & ".doc", FileFormat:= _
wdFormatDocument, LockComments:=False, Password:="",
AddToRecentFiles:= _
True, WritePassword:="", ReadOnlyRecommended:=False,
EmbedTrueTypeFonts:= _
False, SaveNativePictureFormat:=False, SaveFormsData:=False, _
SaveAsAOCELetter:=False
End Sub
****************************************************
I have tried a variation of the file name line above ("Operation" &
Selection.Paste & ".doc", FileFormat:= _) to paste the selected text as the
file name but got the following error:
"Compile Error: Expected Function or variable"
but I'm probably closer to the mark with the line of code as it is in the
above block of code.
Any suggestions?
Anthony