ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   saving a file (https://www.excelbanter.com/excel-programming/372537-saving-file.html)

LearningVBA

saving a file
 
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



Tom Ogilvy

saving a file
 
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

--
Regards,
Tom Ogilvy


"LearningVBA" wrote in message
...
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





All times are GMT +1. The time now is 07:07 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com