Hi
I'm trying to write a macro which will enable me to save a file to a specific folder depending on the first letter of the filename. The code also creates a folder if none already exists. The code below is what I have managed so far but I keep getting a Run-time error '438' I think when I try and define the fchoose variable. Any help would be greatly appreciated.
Function dirExists(dirAndPath) As Boolean
Dim tempVar
On Error Resume Next
tempVar = Dir(dirAndPath & "\*.*", vbDirectory)
If Err = 0 And tempVar <> "" Then
dirExists = True
End If
On Error GoTo 0
End Function
Sub SaveMe()
Dim fname As String
Dim Dname As String
Dim fchoose As Variable
Dim A_to_C As String
Dim D_to_G As String
Dim H_to_K As String
Dim L_to_O As String
Dim P_to_R As String
Dim S_to_T As String
Dim U_to_Z As String
A_to_C = "H:\Acquisitions\Private\Acquisitions\Project Appraisals CBA's\Current CBA's\A - C\"
D_to_G = "H:\Acquisitions\Private\Acquisitions\Project Appraisals CBA's\Current CBA's\D - G\"
H_to_K = "H:\Acquisitions\Private\Acquisitions\Project Appraisals CBA's\Current CBA's\H - K\"
L_to_O = "H:\Acquisitions\Private\Acquisitions\Project Appraisals CBA's\Current CBA's\L - O\"
P_to_R = "H:\Acquisitions\Private\Acquisitions\Project Appraisals CBA's\Current CBA's\P - R\"
S_to_T = "H:\Acquisitions\Private\Acquisitions\Project Appraisals CBA's\Current CBA's\S - T\"
U_to_Z = "H:\Acquisitions\Private\Acquisitions\Project Appraisals CBA's\Current CBA's\U - Z\"
fchoose = Left(Front_Sheet.Range("C2").Characters.Value, 1)
If fchoose = "a" Or fchoose = "b" Or fchoose = "c" Then
If Not dirExists(A_to_C & Front_Sheet.Range("C2").Value) Then MkDir A_to_C & Front_Sheet.Range("C2").Value
Dname = A_to_C & Front_Sheet.Range("C2").Value & "\"
fname = Front_Sheet.Range("C2").Value & Front_Sheet.Range("C6").Value & ".xlsm"
ThisWorkbook.SaveAs Filename:=Dname & fname
End If
End Sub
Bookmarks