Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 74
Default VBA to automatically test for file, update, overwrite

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

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default 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
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 74
Default VBA to automatically test for file, update, overwrite

Thanks Dave,

That should be what I need. I am basically going to use an Access module to
export data and then call an excel macro to open several Excel files, perform
some formatting updates, and then save the files as html files and close
them. I have the rest pretty well completed, I just needed the code to check
to see if one of the files was already open, if so use the open file and then
save the files on exit without prompting the user for overwrite permission.

Thanks Much.

"Dave Peterson" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA to automatically test for file, update, overwrite

Good luck!

Brent E wrote:

Thanks Dave,

That should be what I need. I am basically going to use an Access module to
export data and then call an excel macro to open several Excel files, perform
some formatting updates, and then save the files as html files and close
them. I have the rest pretty well completed, I just needed the code to check
to see if one of the files was already open, if so use the open file and then
save the files on exit without prompting the user for overwrite permission.

Thanks Much.

"Dave Peterson" wrote:

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


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Overwrite tab 1 (1 save per overwite), continous update in tab 2. Excel novice Excel Discussion (Misc queries) 1 August 25th 06 04:40 PM
how do I update a list to overwrite duplicates with new data marshall Excel Discussion (Misc queries) 0 February 21st 06 04:56 PM
how do I update automatically other worksheets in a file Keith Nicholls Excel Discussion (Misc queries) 4 December 21st 05 07:06 PM
automatically update links without opening file sir Lancelot Excel Worksheet Functions 0 July 29th 05 04:05 AM
Automatically update from source when file opens P Flater Excel Discussion (Misc queries) 1 March 25th 05 09:41 PM


All times are GMT +1. The time now is 02:27 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"