Solved

MS Word Macro - Save on open to specific directory

Posted on 2010-08-27
5
534 Views
Last Modified: 2012-06-27
Hi,

I have a Microsoft Word Document and when I open it I want it to automatically save it to a location specified in the code with the same name as the original.

Is this possble to achieve?

Thanks,
0
Comment
Question by:jasocke2
  • 3
5 Comments
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 33540630
Create a macro and call it "AutoExec".

Then you can put your code to save it in the macro and it'll run when you open it.
0
 
LVL 5

Assisted Solution

by:INHOUSERES
INHOUSERES earned 200 total points
ID: 33540674
scrap that.

Press ALT+F11 in the document you want.
On the right, expand "Microsoft Word Objects" and double click "ThisDocument".
Select "Document" and then "open", then put your code in.

e.g.

Private Sub Document_Open()
    FileName = "C:\temp\filename.doc"
    ActiveDocument.SaveAs FileName
End Sub
0
 

Author Comment

by:jasocke2
ID: 33540721
Thank's for your comments.

I work with Excel VBA quite often. Is it the same sort of syntax to Excel?
0
 
LVL 5

Expert Comment

by:INHOUSERES
ID: 33540767
Most of office collection has the same syntax. Access is probably the only exception, but not by much.

For example:

Excel: ActiveWorkbook
Word: ActiveDocument
Powerpoint: ActivePresentation
0
 
LVL 59

Accepted Solution

by:
Chris Bottomley earned 300 total points
ID: 33540829
If yoiu simply save then the active document takes the save file name and you are no longer working on the original so try the following which saves the document, (change "c:\deleteme\" & ActiveDocument.FullName for your saved file name).

Chris


Private Sub Document_Open()
    ActiveDocument.Save
    Application.Documents.Add ActiveDocument.FullName
    ActiveDocument.SaveAs "c:\deleteme\" & ActiveDocument.FullName
    ActiveDocument.Close
End Sub

Open in new window

0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User Beware!  This is a rather permanent solution to removing your email from an exchange server.  The only way to truly go back is to have your exchange administrator restore your mailbox from backups.  This is usually the option of last resort.  A…
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question