VBA to automatically test for file, update, overwrite
What does activate the current file mean--the sites.xls workbook?
Did you want to save the sites.xls and close it? I'm not sure why opening,
saving, closing would accomplish.
I'm confused about what current and existing mean in your question.
But maybe this will get you started.
Dim TestWkbk as workbook
set testwkbk = nothing
on error resume next
set testwkbk = workbooks("sites.xls")
on error goto 0
if testwkbk is nothing then
set testwkbk = workbooks.open(filename:="d:\data\sites.xls")
end if
testwkbk.close savechanges:=true
'or to close the workbook that holds the code
thisworkbook.close savechanges:=true
Brent E wrote:
Good Morning,
I am looking for the VBA code to:
A. Test if an Excel file is already open, e.g. D:\Data\Sites.xls. If yes,
activate current file. If no, open file.
[Do whatever...]
B. Then automatically save the file and overwrite prompt as 'Yes' for
existing file on close? So the module does not pause waiting for a yes prompt
from the user to overwrite.
Thanks
--
Dave Peterson
|