Macro to close open excel sheet

dreammaker

New Member
Joined
May 26, 2010
Messages
17
Hi all,

I am trying to use macros in Access to close both an open excel worksheet based on tables in Access and the access database prior to updating all my tables from a 3rd party software,

Part of the 3rd party software functionality is the use of .bat files, Therefore to open the access database or excel workbook is relatively easy.

My plan was to use the .bat files

@echo off
SET datafile=DB reports
SET macro=Open

REM ---------------- Do not change below this line ----------------
ECHO Interface running for %datafile%.
"C:\Program Files\Microsoft Office\Office12\MSACCESS" "c:\FAS interfaces\%datafile%.mdb" /x %macro%

The above code will allow me to open my database DB reports, and run the macro called Open in the access database,

Now the hard bit,

I need to create a Close Marco, which will see if there is a file call Reports.xls open and if so, close it, without saving, and then close the database DB reports,

The latter bit is a simple close command, does anyone have any ideas on how to kill the excel workbook prior to closing the database.

Many thanks in advance.

DM
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi all,

I am trying to use macros in Access to close both an open excel worksheet based on tables in Access and the access database prior to updating all my tables from a 3rd party software,

Part of the 3rd party software functionality is the use of .bat files, Therefore to open the access database or excel workbook is relatively easy.

My plan was to use the .bat files

@echo off
SET datafile=DB reports
SET macro=Open

REM ---------------- Do not change below this line ----------------
ECHO Interface running for %datafile%.
"C:\Program Files\Microsoft Office\Office12\MSACCESS" "c:\FAS interfaces\%datafile%.mdb" /x %macro%

The above code will allow me to open my database DB reports, and run the macro called Open in the access database,

Now the hard bit,

I need to create a Close Marco, which will see if there is a file call Reports.xls open and if so, close it, without saving, and then close the database DB reports,

The latter bit is a simple close command, does anyone have any ideas on how to kill the excel workbook prior to closing the database.

Many thanks in advance.

DM

Here is a line of code to kill a workbook if it exists.

If Dir(CurrentProject.Path & "\Peer Review Country Analysis Report.xls") <> "" Then Kill CurrentProject.Path & "\Peer Review Country Analysis Report.xls"
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,952
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top