Solved

MS Word Macro - Save on open to specific directory

Posted on 2010-08-27
5
532 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now