Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS Word Macro - Save on open to specific directory

Posted on 2010-08-27
5
Medium Priority
?
539 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 800 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 1200 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
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:
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.

783 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