Saving a file in a specific folder

G

GaryJsdad

I want to help tweak a small VBA template that has been developed for
work and would appreciate some pointers to get me started.

The template includes a user form with a series of edit boxes. The
file is named based on a combination of two fields. That works
perfectly so far.

For reasons I don't clearly understand, the files must be saved in
folders based on alphabetization. That is to say, a file named
smith123 would need to be in the folder named "S". It gets a bit more
specific in that they have broken down each letter as well so that the
"S" folder has sub-folders named "SA-SD", "SE-SM" etc.... The biggest
problem of course is that users are not always getting the files in
the proper location.

I've never had to work on a project that I had to match the first few
letters of a variable. Any pointers to get me started would be
appreciated.

Gary
 
H

Helmut Weber

Hi Gary,

you can overwrite the filesave command.
Then you need some citeria to decide,
whether it is an ordinary file or a YourSystem file.
I call it YourSystem to prevent confusion with Windows system files.

You may use the document's template to check,
whether it is an ordinary file or not.

Then I'd suggest to build the file's fullname.

Lets say form the fields in the doc you get "smith123".

Sub FileSave()
Const pathpart1 = "c:\yoursystem\"

Dim pathpart2 As String
Dim pathpart3 As String
Dim pathtempo As String
Dim xfilename As String
Dim xfullname As String

' just one way
'If ActiveDocument.AttachedTemplate <> "MyTemplate.dot" Then
'Exit Sub
'End If

xfilename = ("Smith123")
pathpart2 = UCase(Left(xfilename, 1))
pathtempo = UCase(Mid(xfilename, 1, 1))

Select Case pathtempo
Case "A" To "D":
pathpart3 = pathpart2 & "A-"
pathpart3 = pathpart3 & pathtempo & "D"
Case "E" To "M":
pathpart3 = pathpart2 & "E-"
pathpart3 = pathpart3 & pathtempo & "M"
Case "N" To "R":
pathpart3 = pathpart2 & "N-"
pathpart3 = pathpart3 & pathtempo & "R"
Case "S" To "Z":
pathpart3 = pathpart2 & "S-"
pathpart3 = pathpart3 & pathtempo & "Z"
End Select
xfullname = pathpart1
xfullname = xfullname & pathpart2 & "\"
xfullname = xfullname & pathpart3 & "\"
xfullname = xfullname & "Smith123" & ".doc"

MsgBox xfullname ' now save it
End Sub

I'm assuming, that the necessary folders do exist.
Otherwise they can be created programmtically.

Lots of error handling is missing, too.

One could even scan all folders and subfolders
and put astray files back to the location where thy should be.
Lets say, once per day between 3 and 4 in the morning, etc...

HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
G

GaryJsdad

Thank you for your quick reply Helmut. I'll have a look at that
code. I particularly thank your for an actual code example to
dissect. I was just looking for pointers for where to look, this
gives me a skeleton to expand on.

Thanks

Gary
 

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