View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
GS[_5_] GS[_5_] is offline
external usenet poster
 
Posts: 226
Default ActiveWorkbook.Save saves to wrong directory

Akihito Yamashiro brought next idea :
Check if the book is saved on a file system.
ActiveworkBook.Path can be used for the purpose.

Sub Main()
If ActiveWorkbook.Path = "" Then
MsgBox "Save the file before the process."
Exit Sub
Else
ActiveWorkbook.Save
'Do something here.
End If
End Sub


If this doesn't help you, the file may be in the 'Program Files'
folder and the PC is Windows Vista or 7,
the file path may be redirected to the VirtualStore folder.


How does this get the correct path? If files are currently saving to
incorrect folders then the 'assumed path' has to be removed from the
equation. Storing the correct path for a workbook as a CustomProperty
in the workbook file allows code to retrieve it without assumption.

While bruce2g states his users aren't savvy enough to use SaveAs to
save files to the wrong folder, doesn't meant that someone isn't
deliberately moving files from one place to another. Using the
CustomProperty approach means the correct path is imbedded in the xls
file, so no matter where it's opened from it can always get saved back
into the correct folder via code.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc