PDA

View Full Version : Solved: Renaming doc without SaveAs



Humbled
08-01-2008, 03:13 AM
My document will be retrieved by users from a website or shared drive. The document is a form, and through macro magic (found on this forum) emails the completed form via Outlook to a mailbox.

I am currently renaming the document and then sending. I need the doc sent to the mailbox to have a specific name so those who handle the form have some idea about what's needed before they open it. This works.

'************************************************************
' Rename document to ROC-CUST-TIMESTAMP then save it
'************************************************************
Store = ActiveDocument.Bookmarks("PHCY").Range.Text
SvTime = Format(Now, "yymmdd") & Format(Now, "hhmmss")
FileName = "ROC-" & Store & " " & SvTime
ActiveDocument.SaveAs FileName

'************************************************************
' Open a new e-mail message
'************************************************************
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem 'and add the detail to it
.To = email.addy@myplace.com 'send to this address
.Subject = Store & " [" & strTYP & " " & Format(NeedDt, "yymmdd") & "]"
.Body = "See attached document." ' This is the message body text
.Attachments.Add Source:=ActiveDocument.FullName, Type:=olByValue
.Send
End With


Now ... since a copy will be saved in the user's sent items folder, there's really no need to keep a local copy. I'd like to rename (or assign a new name) without the SaveAs.

The following doesn't work ... complains about a read-only property.

'************************************************************
' Rename document to ROC-CUST-TIMESTAMP then save it
'************************************************************
Store = ActiveDocument.Bookmarks("PHCY").Range.Text
SvTime = Format(Now, "yymmdd") & Format(Now, "hhmmss")
FileName = "ROC-" & Store & " " & SvTime
ActiveDocument.Name = FileName


As a last resort, I suppose I could save it, email it, then delete it - but hoping for something other than a last resort.

Thanks in advance.

lucas
08-01-2008, 10:54 AM
Why not use a word template........clones from the template.....run your code to savas, rename and email it and close the new document without saving changes....voila.

Humbled
08-01-2008, 11:04 AM
After reading many other threads of a similiar nature, this seems to be the way to go. I've been trying that for a couple of days now, but can't get it to work properly either.

Rather than have this topic shift, I'll mark this one solved and post another with the template problems I'm having.

Thanks!