Link to home
Create AccountLog in
Avatar of JohnRobinAllen
JohnRobinAllenFlag for Canada

asked on

Save a document with a *.bak extension using VBA

In Word using VBA, if I open a file with a *.doc extension or a *.docx extension and I want to save the file with a *.bak extension, how can I do that? Right now all I get is a *.bak.doc or *.bak.docx extension. I want to override the default extension, but perhaps that is impossible.
    Thanks!
     J.R. Allen, Priddis, Alberta, Canada


 
ASKER CERTIFIED SOLUTION
Avatar of Corey Habbas
Corey Habbas
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
There is a name key word.  You can try...

Name "C:\File.doc" As "C:\File.bat"

Also, I forgot to ask what your code looks like.  Can you paste the snippet of your code that isn't working?  This will help me make sure I don't suggest the same commands as what you are using.  Thanks!
SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of JohnRobinAllen

ASKER

    The description of my problem implied but did not explicitly state that the solution would require changing the format of the file. Graham Skan’s elegant solution does not work if the file is a .docx or .docm file.
     Byten’s code gives a link to show the different formats one can specify. Since by the time I need to save a file under a backup name, I already will have the extension, it is easy to use Select Case to specify which format to use.
     Since I can change the name with either the Name command in byten’s code or with the Replace command in Graham Skan’s code, I can use either. The key is the format specification. At present I consider the problem solved, and I have boosted the points awarded to 300 to give 200 to byten and 100 to Graham Skan.
     Thanks for the help. Beyond solving my problem the comments also increased my knowledge of VBA in general.
I posted comments at the end of the discussion.