Save As with Active Document Name +1 
Author Message
 Save As with Active Document Name +1

I would like to save the current active document with the same name but with
the number 1 added and in text file format.

E.g. CurrentFile.doc saved as CurrentFile1.txt

Here is what I am currently using, but it requires the file to be named the
same way each time.

============
ActiveDocument.SaveAs FileName:="TextFile1.txt", FileFormat:=wdFormatText
============

I can get the file to save in a different format (from Word Doc to text
file, but I would like to have the numberal added to what ever the current
active file name is.

Any help appreciated.

Pete



Mon, 13 Oct 2003 02:12:24 GMT  
 Save As with Active Document Name +1
Pete,

Quote:
> I would like to save the current active document with the same name but
> with the number 1 added and in text file format.

As for the matter of appending a number to the file name, have a look at
the following page on the Word MVP site.

http://www.mvps.org/word/FAQs/MacrosVBA/SaveIncrementedFilename.htm

Take Care

Gary



Mon, 13 Oct 2003 04:14:32 GMT  
 Save As with Active Document Name +1

Quote:

> I would like to save the current active document with the same name but with
> the number 1 added and in text file format.

> E.g. CurrentFile.doc saved as CurrentFile1.txt

> Here is what I am currently using, but it requires the file to be named the
> same way each time.

> ============
> ActiveDocument.SaveAs FileName:="TextFile1.txt", FileFormat:=wdFormatText
> ============

> I can get the file to save in a different format (from Word Doc to text
> file, but I would like to have the numberal added to what ever the current
> active file name is.

> Any help appreciated.

> Pete

You can build the new filename like this:

myFileName$ = ActiveDocument.Name
If InStr(1, myFileName$, ".") > 0 Then
    myFileName$ = Left$(myFileName$, InStr(1, myFileName$, ".") - 1)
End If
newFileName$=myFileName$ + "1"
ActiveDocument.SaveAs FileName:=newFileName$, FileFormat:=wdFormatText

(The extension ".txt" is added automatically)

But you can do better than that ;)

The following macro will save the document with a new "version-number" any
time you save it (e.g., document called "Mydoc.doc" will be saved as
"Mydoc001.doc" and "Mydoc001.txt", the next time under
"Mydoc002.doc"/"Mydoc002.txt" ...). You would have to change it some if your
system only supports short 8.3 file-names.
(I like the versioning done in big operating systems a lot, and with
hard-disks being cheap, it doesn't hurt keeping dozens of old versions around,
as long as they are named consistently)

Greetings, Klaus

Sub SaveNewVersion()

FName$ = ActiveDocument.Name

' Delete extension ".XXX":
If InStr(1, FName$, ".") > 0 Then
    FName$ = Left$(FName$, InStr(1, FName$, ".") - 1)
End If

' Separate filename into "root" and verion number:
Version$ = ""
While InStr(1, "0123456789", Right$(FName$, 1)) > 0
    Version$ = Right$(FName$, 1) + Version$
    FName$ = Left$(FName$, Len(FName$) - 1)
Wend

' For files without version number:
If Version$ = "" Then
    Version$ = "000"
End If

' Build new version number
VersNum = Val(Version$) + 1
VersLen = Len(Version$)
Version$ = LTrim(Str$(VersNum))
While Len(Version$) < VersLen
    Version$ = "0" + Version$
Wend
FName$ = FName$ + Version$

With Dialogs(wdDialogFileSaveAs)
    .Name = FName$
    .Format = wdFormatDoc
    .Show
End With
With Dialogs(wdDialogFileSaveAs)
    .Name = FName$
    .Format = wdFormatText
    .Show
End With

End Sub



Mon, 13 Oct 2003 05:30:18 GMT  
 Save As with Active Document Name +1

Quote:

> As for the matter of appending a number to the file name, have a look at
> the following page on the Word MVP site.

> http://www.mvps.org/word/FAQs/MacrosVBA/SaveIncrementedFilename.htm

Oh my, shows how much I've still got to learn :(

Dave Rado does things with a tenth of the code I need; seems he's soaring when
I'm just plodding along!

Klaus



Mon, 13 Oct 2003 06:04:24 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. email active document - without saving it

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

3. Active Document/Property Bag - Prompt to save changes?

4. Give a document a name without saving

5. Saving document with Date & Time in Name

6. Save document with unique name...

7. Saving document with Bookmark as file name

8. Save a Document with Bookmarks as part of file name

9. Dates, Field Updates and Document Naming/Saving

10. Document Name for save

11. Save document with current date in the file name

12. Macro to insert text or document into active document

 

 
Powered by phpBB® Forum Software