Doing a SaveAs without renaming the working document 
Author Message
 Doing a SaveAs without renaming the working document

Hello everyone,

I've been trying to figure out how I could allow a user to save a copy of
their document under another name without renaming their working document
(sort of a publish feature).  I found out quickly enough that copying the
file to another name using FileCopy doesn't work when the document is open.
The only other approach I've thought of involves ugly document swapping:
save work document, perform saveas, close new document, reopen work
document.  I've just about given up on an easier and more elegant method,
but I figured I'd ask anyway.  Any advice or insight is welcome!

Thanks

Sebastien



Fri, 28 Jun 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
Hi ibby

Thanks a lot for the info, it does exactly what I want it to do!  But I'm
wondering if the Scripting object is supported on all of the following
platforms: Win95, Win98, NT4 and Win2K.  Is it browser dependent (i.e. does
IE have to be installed), or is it present by default?

Thanks!

Sebastien

Quote:

> Hi Sebastion,

> Try the following. It copies the last saved instance of the ActiveDocument
> to a folder called "C:\My Extract". It renames this file
> "myCopy_"<originalfilename>

> eg: if you have a file open called "myDoc.doc", it will copy the last
saved
> instance of the file to C:\My Extract and rename it "myCopy_myDoc.doc".
> Obviously, the current document needs to be saved at least once for this
to
> work.

> -------------------------------------------------------------

> Public Sub CopyOpenFile()

> Dim fso As Object
> Dim myFile As Object
> Dim strName As String
> Dim strFullName As String
> Dim strPath As String
> Dim msg As String

> msg = "Current document has not been saved." & _
> vbCr & "You must save it before you can " & _
> "create a copy."

> strName = ActiveDocument.Name
> strFullName = ActiveDocument.FullName
> strPath = ActiveDocument.Path

> If strPath = "" Then
>     MsgBox msg
>     Exit Sub
> End If

> Set fso = CreateObject("Scripting.FileSystemObject")
> Set myFile = fso.GetFile(strFullName)
> myFile.Copy ("C:\My Extract\" & "myCopy_" & strName)

> End Sub

> ----------------------------------------------------------------

> Hope this helps.
> Regards
> ibby

> Please post any replies to the **newsgroup** so that others in the
newsgroup
> may contribute or benefit.



> | Hello everyone,
> |
> | I've been trying to figure out how I could allow a user to save a copy
of
> | their document under another name without renaming their working
document
> | (sort of a publish feature).  I found out quickly enough that copying
the
> | file to another name using FileCopy doesn't work when the document is
> open.
> | The only other approach I've thought of involves ugly document swapping:
> | save work document, perform saveas, close new document, reopen work
> | document.  I've just about given up on an easier and more elegant
method,
> | but I figured I'd ask anyway.  Any advice or insight is welcome!
> |
> | Thanks
> |
> | Sebastien
> |
> |



Fri, 28 Jun 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
Hi Sebastion,

Try the following. It copies the last saved instance of the ActiveDocument
to a folder called "C:\My Extract". It renames this file
"myCopy_"<originalfilename>

eg: if you have a file open called "myDoc.doc", it will copy the last saved
instance of the file to C:\My Extract and rename it "myCopy_myDoc.doc".
Obviously, the current document needs to be saved at least once for this to
work.

-------------------------------------------------------------

Public Sub CopyOpenFile()

Dim fso As Object
Dim myFile As Object
Dim strName As String
Dim strFullName As String
Dim strPath As String
Dim msg As String

msg = "Current document has not been saved." & _
vbCr & "You must save it before you can " & _
"create a copy."

strName = ActiveDocument.Name
strFullName = ActiveDocument.FullName
strPath = ActiveDocument.Path

If strPath = "" Then
    MsgBox msg
    Exit Sub
End If

Set fso = CreateObject("Scripting.FileSystemObject")
Set myFile = fso.GetFile(strFullName)
myFile.Copy ("C:\My Extract\" & "myCopy_" & strName)

End Sub

----------------------------------------------------------------

Hope this helps.
Regards
ibby

Please post any replies to the **newsgroup** so that others in the newsgroup
may contribute or benefit.


| Hello everyone,
|
| I've been trying to figure out how I could allow a user to save a copy of
| their document under another name without renaming their working document
| (sort of a publish feature).  I found out quickly enough that copying the
| file to another name using FileCopy doesn't work when the document is
open.
| The only other approach I've thought of involves ugly document swapping:
| save work document, perform saveas, close new document, reopen work
| document.  I've just about given up on an easier and more elegant method,
| but I figured I'd ask anyway.  Any advice or insight is welcome!
|
| Thanks
|
| Sebastien
|
|



Sat, 29 Jun 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
Hi again Sebastion,

If you assign your macro to a custom commandbar button, you can add some
code to save your document first, before saving the copy - this way your
saved documents will always be synchronized.

--
Hope this helps.
Regards
ibby

Please post any replies to the **newsgroup** so that others in the newsgroup
may contribute or benefit.

| Hi Sebastion,
|
| Try the following. It copies the last saved instance of the ActiveDocument
| to a folder called "C:\My Extract". It renames this file
| "myCopy_"<originalfilename>
|
| eg: if you have a file open called "myDoc.doc", it will copy the last
saved
| instance of the file to C:\My Extract and rename it "myCopy_myDoc.doc".
| Obviously, the current document needs to be saved at least once for this
to
| work.
|
| -------------------------------------------------------------
|
| Public Sub CopyOpenFile()
|
| Dim fso As Object
| Dim myFile As Object
| Dim strName As String
| Dim strFullName As String
| Dim strPath As String
| Dim msg As String
|
| msg = "Current document has not been saved." & _
| vbCr & "You must save it before you can " & _
| "create a copy."
|
| strName = ActiveDocument.Name
| strFullName = ActiveDocument.FullName
| strPath = ActiveDocument.Path
|
| If strPath = "" Then
|     MsgBox msg
|     Exit Sub
| End If
|
| Set fso = CreateObject("Scripting.FileSystemObject")
| Set myFile = fso.GetFile(strFullName)
| myFile.Copy ("C:\My Extract\" & "myCopy_" & strName)
|
| End Sub
|
| ----------------------------------------------------------------
|
| Hope this helps.
| Regards
| ibby
|
| Please post any replies to the **newsgroup** so that others in the
newsgroup
| may contribute or benefit.
|
|
|


| | Hello everyone,
| |
| | I've been trying to figure out how I could allow a user to save a copy
of
| | their document under another name without renaming their working
document
| | (sort of a publish feature).  I found out quickly enough that copying
the
| | file to another name using FileCopy doesn't work when the document is
| open.
| | The only other approach I've thought of involves ugly document swapping:
| | save work document, perform saveas, close new document, reopen work
| | document.  I've just about given up on an easier and more elegant
method,
| | but I figured I'd ask anyway.  Any advice or insight is welcome!
| |
| | Thanks
| |
| | Sebastien
| |
| |
|
|



Sat, 29 Jun 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
Hi again Sebastien,

Another way of creating a copy of your open document in another directory.
The advantage of this is that it creates a copy of the open document as it
stands ie: without having to save changes to the open document first. It
also avoids having to use the "Scripting.FileSystemObject".

I wonder if someone can try this in Word2000 as it looks like a "bug" to
me - Documents.Add is supposed to create a document based on a template, not
based on another document. And furthermore, it creates a copy that includes
any unsaved modifications !!

-----------------------------------------------------------------

Dim myCopy As Document
Dim strName As String
Dim strPath As String
Dim myCopyFolder As String
Dim msg1 As String
Dim msg2 As String

myCopyFolder = "C:\My Extract"

msg1 = "Current document has never been saved." & _
vbCr & "You must save it before you can " & _
"create a copy."

msg2 = "A copy of the active document (as is) has " & _
"been created in folder '" & myCopyFolder & "'."

strName = ActiveDocument.Name
strPath = ActiveDocument.Path

If strPath = "" Then
    MsgBox msg
    Exit Sub
End If

Set myCopy = Documents.Add(ActiveDocument.FullName)
myCopy.SaveAs myCopyFolder & "\" & strName
myCopy.Close

MsgBox msg2

-----------------------------------------------------------------

Hope this helps.
Regards
ibby

Please post any replies to the **newsgroup** so that others in the newsgroup
may contribute or benefit.


| Hi ibby
|
| Thanks a lot for the info, it does exactly what I want it to do!  But I'm
| wondering if the Scripting object is supported on all of the following
| platforms: Win95, Win98, NT4 and Win2K.  Is it browser dependent (i.e.
does
| IE have to be installed), or is it present by default?
|
| Thanks!
|
| Sebastien
|

| > Hi Sebastion,
| >
| > Try the following. It copies the last saved instance of the
ActiveDocument
| > to a folder called "C:\My Extract". It renames this file
| > "myCopy_"<originalfilename>
| >
| > eg: if you have a file open called "myDoc.doc", it will copy the last
| saved
| > instance of the file to C:\My Extract and rename it "myCopy_myDoc.doc".
| > Obviously, the current document needs to be saved at least once for this
| to
| > work.
| >
| > -------------------------------------------------------------
| >
| > Public Sub CopyOpenFile()
| >
| > Dim fso As Object
| > Dim myFile As Object
| > Dim strName As String
| > Dim strFullName As String
| > Dim strPath As String
| > Dim msg As String
| >
| > msg = "Current document has not been saved." & _
| > vbCr & "You must save it before you can " & _
| > "create a copy."
| >
| > strName = ActiveDocument.Name
| > strFullName = ActiveDocument.FullName
| > strPath = ActiveDocument.Path
| >
| > If strPath = "" Then
| >     MsgBox msg
| >     Exit Sub
| > End If
| >
| > Set fso = CreateObject("Scripting.FileSystemObject")
| > Set myFile = fso.GetFile(strFullName)
| > myFile.Copy ("C:\My Extract\" & "myCopy_" & strName)
| >
| > End Sub
| >
| > ----------------------------------------------------------------
| >
| > Hope this helps.
| > Regards
| > ibby
| >
| > Please post any replies to the **newsgroup** so that others in the
| newsgroup
| > may contribute or benefit.
| >
| >
| >


| > | Hello everyone,
| > |
| > | I've been trying to figure out how I could allow a user to save a copy
| of
| > | their document under another name without renaming their working
| document
| > | (sort of a publish feature).  I found out quickly enough that copying
| the
| > | file to another name using FileCopy doesn't work when the document is
| > open.
| > | The only other approach I've thought of involves ugly document
swapping:
| > | save work document, perform saveas, close new document, reopen work
| > | document.  I've just about given up on an easier and more elegant
| method,
| > | but I figured I'd ask anyway.  Any advice or insight is welcome!
| > |
| > | Thanks
| > |
| > | Sebastien
| > |
| > |
| >
| >
|
|



Mon, 01 Jul 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
Hi Ibby,

Quote:
> I wonder if someone can try this in Word2000 as it looks like a "bug" to
> me - Documents.Add is supposed to create a document based on a template,
not
> based on another document. And furthermore, it creates a copy that
includes
> any unsaved modifications !!

Works in Word97 as well as long as the document has been saved for at least
one time. Doesn't matter if the file is dirty or not, it creates an exact
copy of the current document.

------------------------------
sTemp = ActiveDocument.FullName
Documents.Add Template:=sTemp
-------------------------------

Hope this helps,
regards,
Astrid
Microsoft Word MVP



Mon, 01 Jul 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
Hi Ibby,

I've just tried it with Word2000 and it works.  Now if we could only know
whether it's an undocumented "feature".  I would be worried about having it
not work in future releases of Word...

Sebastien


Quote:
> Hi Astrid,

> | Works in Word97 as well .................

> Yes I know. I have only got Word97 so I was looking for someone to test in
> Word2000. Is this a documented/accepted way of creating a copy of a
document
> ? I came across it by accident. The Documents.Add method is supposed to
> create a new document based on a template - not based on another document
!!

> Anyway, nice to "talk" to you again.

> Regards
> ibby



Mon, 01 Jul 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
Hi Astrid,

| Works in Word97 as well .................

Yes I know. I have only got Word97 so I was looking for someone to test in
Word2000. Is this a documented/accepted way of creating a copy of a document
? I came across it by accident. The Documents.Add method is supposed to
create a new document based on a template - not based on another document !!

Anyway, nice to "talk" to you again.

Regards
ibby



Tue, 02 Jul 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
Hi Sebastien,

| I've just tried it with Word2000 and it works.  Now if we could only know
| whether it's an undocumented "feature".  I would be worried about having
it
| not work in future releases of Word...

Thanks for testing testing it and, yes, the worry is that it may be a "bug"
that gets fixed in a future release - but I guess we can only code in the
present and modify in future releases if the behaviour changes.

Regards
ibby



Tue, 02 Jul 2002 03:00:00 GMT  
 Doing a SaveAs without renaming the working document
personally I like the 'feature' (read bug)

--
Will Rickards [MVP Word]
Software Engineer
http://members.home.net/wrickard

Please post ALL replies/requests to the newsgroup for the benefit of the newsgroup.
disclaimer: Use of any information/code provided is at your own risk.
My e-mail address has been modified to prevent ****.

Quote:

> Hi Sebastien,

> | I've just tried it with Word2000 and it works.  Now if we could only know
> | whether it's an undocumented "feature".  I would be worried about having
> it
> | not work in future releases of Word...

> Thanks for testing testing it and, yes, the worry is that it may be a "bug"
> that gets fixed in a future release - but I guess we can only code in the
> present and modify in future releases if the behaviour changes.

> Regards
> ibby



Thu, 18 Jul 2002 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. SaveAs without changing current document

2. doing a saveas gives empty body

3. Word 2000 VBA - SaveAs Method Overwrites Without Warning

4. SaveAs Method on a Workbook object without confirmation ?

5. Copy a document but without the document template

6. Document Statistics Without Opening a Document

7. How to keep a document hidden after using a SaveAs dialog

8. Stop SaveAs from changing active document

9. Creating a procedure from active document (Save) or (SaveAs)

10. Bypass SaveAs .PDF dialog box doesn't work

11. Saveas wdFormatHTML not worked!

12. SaveAs wdFormatHTML -- not working

 

 
Powered by phpBB® Forum Software