Setting a Path in Word VBA

P

paulinec

I found the following macro on the internet (from someone else's
question)and it is working for me, except that it is saving the documents all
to my C drive.
How can I program a path eg. C:\A_Data\Word\Merge

Dim x As Long
Dim Sections As Long
Dim Doc As Document

Application.ScreenUpdating = False
Application.DisplayAlerts = False

Set Doc = ActiveDocument

Sections = Doc.Sections.Count
For x = Sections - 1 To 1 Step -1
Doc.Sections(x).Range.Copy
Documents.Add
ActiveDocument.Range.Paste
ActiveDocument.SaveAs (Doc.Path & "\" & x & ".doc")
ActiveDocument.Close False
Next x

Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
Hoping someone can help me with this.
 
M

macropod

Hi Pauline,

Simply change the 'Doc.Path' reference to your preferred path. So, instead
of:
ActiveDocument.SaveAs (Doc.Path & "\" & x & ".doc")
use:
ActiveDocument.SaveAs ("C:\A_Data\Word\Merge" & "\" & x & ".doc")

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top