Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic directories thru Word VBA

Status
Not open for further replies.

handlebars

Technical User
Feb 18, 2003
270
GB
- is it possible to code in which directory a document is saved into (not the file name) dependent on the system date - i.e. if the date is between Jan and march it will be saved into Quarter One 2003, if next quarter - then Q2, Q3 etc. Can these folders be created automatically by word if they do not exist?

Any help would be appresiated.
 
Handlebars

This is created in Excel. I'm pretty sure that it will also work in Word.

Sub CreateQuarterDir()
Dim M As Integer
Dim Q As String
Dim RootDir As String
Dim SaveDir As String

RootDir = "C:\This Year" 'Set your root dir
M = Month(Now()) 'Find Month Number
Select Case M

Case M = 1, M = 2, M = 3 'Select action dependent on month
Q = "Quarter1" 'and your financial year

Case M = 4, M = 5, M = 6
Q = "Quarter2"

Case M = 7, M = 8, M = 9
Q = "Quarter3"

Case Else
Q = "Quarter4"

End Select
SaveDir = Q

On Error Resume Next 'Set error to goto next line
SaveDir = RootDir & "\" & SaveDir 'Create the full SaveDir string
ChDir SaveDir 'Try to change to that dir
If Err = 76 Then MkDir SaveDir 'Dir does not exist so create it
Err = 0 'Turn off error
End Sub

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top