Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2007

Tip: Looking for answers? Try searching our database.

Saving document with new name via vba

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
rachitm@gmail.com - 26 Jun 2007 22:08 GMT
Hi,

Following is the scenario:

I have a document named: CCPC_01.doc
The user opens up the document makes the changes.

I want a macro which would save the updated version of this document
(doesnt matter if its in the same folder) with the following name:
CCPC_01_locked.doc

All Help is Appreciated
rachitm@gmail.com - 26 Jun 2007 22:33 GMT
To restate what I would like help with is that I want a macro which
will add "_locked".doc at the end of the current name of the document
and save it as a new file.

Thanks
Tony Strazzeri - 27 Jun 2007 04:57 GMT
On Jun 27, 7:33 am, rach...@gmail.com wrote:
> To restate what I would like help with is that I want a macro which
> will add "_locked".doc at the end of the current name of the document
> and save it as a new file.
>
> Thanks

Hi Rach,

Try this.
       Dim strNewName As String
       Dim dt As Single    'Location of the dot before the filename
extension

       strNewName = ActiveDocument.FullName
       dt = InStrRev(strNewName, ".")
       strNewName = Left(strNewName, dt - 1) & "_Locked" &
Mid(strNewName, dt)
       ActiveDocument.SaveAs FileName:=strNewName

This will keep save the document to the same folder and preserve the
extension.
Of course this new doc now becomes the activedociument so if you then
want to go back/work on the original document you have to close this
new one and open the original.

Cheers
TonyS.
rachitm@gmail.com - 27 Jun 2007 20:43 GMT
Thanks Tony , this works perfect!

Got a question, is there a way that the original document can still be
open after it saves it with the new document name.....?
Russ - 30 Jun 2007 01:16 GMT
Rachitm,

> Thanks Tony , this works perfect!
>
> Got a question, is there a way that the original document can still be
> open after it saves it with the new document name.....?
A simple modification of Tony's routine should do want you want.
The original, unmodified document is reopened.

Dim strOriginalName As String
Dim strNewName As String
Dim dt As Single

strOriginalName = ActiveDocument.FullName
strNewName = ActiveDocument.FullName
dt = InStrRev(strNewName, ".")
strNewName = Left(strNewName, dt - 1) & "_Locked" & _
  Mid(strNewName, dt)
ActiveDocument.SaveAs FileName:=strNewName
'ActiveDocument.Close
Documents.Open FileName:=strOriginalName

UnComment the .Close line, if that is what you want.
Signature

Russ

drsmN0SPAMikleAThotmailD0Tcom.INVALID

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.