saving a file

L

LearningVBA

Is there a reason why the file gets saved into My Documents folder instead
of a specific location on D drive? I ran the line carefully and it looks
fine but it does not get saved in the expected folder. The ChDir appears to
be on strike!

Thank you for your help

Function saveFile(ByVal thisDir As String, ByVal thisFile As String)
Dim isFileExist As Boolean
Dim fullPath As String
fullPath = thisDir & thisFile
isFileExist = fileInExistence(thisDir, thisFile)
If isFileExist Then
Kill thisDir & thisFile
ChDir thisDir
ActiveWorkbook.SaveAs fileName:=thisFile,
FileFormat:=xlWorkbookNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False
Else
ChDir thisDir
ActiveWorkbook.SaveAs fileName:=thisFile, FileFormat:=xlNormal,
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,
CreateBackup:=False
End If
End Function
 
T

Tom Ogilvy

chdir sets the default directory for the specified drive, but it doesn't
change the default drive.

Function saveFile(ByVal thisDir As String, ByVal thisFile As String)
Dim isFileExist As Boolean
Dim fullPath As String
fullPath = thisDir & thisFile
isFileExist = fileInExistence(thisDir, thisFile)
If isFileExist Then
Kill thisDir & thisFile
ChDrive thisDir
ChDir thisDir
ActiveWorkbook.SaveAs fileName:=thisFile,
FileFormat:=xlWorkbookNormal, Password:="", WriteResPassword:="",
ReadOnlyRecommended:=False, CreateBackup:=False
Else
ChDrive thisDir
ChDir thisDir
ActiveWorkbook.SaveAs fileName:=thisFile, FileFormat:=xlNormal,
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False,
CreateBackup:=False
End If
End Function
 

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

Similar Threads


Top