ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel document not saving (https://www.excelbanter.com/excel-programming/384928-excel-document-not-saving.html)

Kevin

Excel document not saving
 
From VBA, I start with an excel workbook with one worksheet. Then, I open a
second excel file (with one worksheet), edit it and bring the tab into the
original workbook. So, there are now two worksheets in the original workbook.
Then save it - this works. Then, do it again... Open a new second excel file,
edit the tab and bring it into existing workbook. Now there are 3 tabs in the
original workbook. I try to save and it gives an error "document not
saved"... using the following code:

Workbooks.Open ("\\...path\Summary.xls")
Windows("Summary.xls").Activate
Sheets("Tab1").Select
Sheets("Tab1").Move befo=Workbooks(Original).Sheets(1)
ActiveWorkbook.Save


Jim Jackson

Excel document not saving
 
If you are talking about trying to save the original workbook add this line
just below the "Save" line.
ThisWorkbook.Activate

Or instead of ActiveWorkbook.Save use This Workbook.Save.
--
Best wishes,

Jim


"Kevin" wrote:

From VBA, I start with an excel workbook with one worksheet. Then, I open a
second excel file (with one worksheet), edit it and bring the tab into the
original workbook. So, there are now two worksheets in the original workbook.
Then save it - this works. Then, do it again... Open a new second excel file,
edit the tab and bring it into existing workbook. Now there are 3 tabs in the
original workbook. I try to save and it gives an error "document not
saved"... using the following code:

Workbooks.Open ("\\...path\Summary.xls")
Windows("Summary.xls").Activate
Sheets("Tab1").Select
Sheets("Tab1").Move befo=Workbooks(Original).Sheets(1)
ActiveWorkbook.Save


Kevin

Excel document not saving
 
Thanks for your help. I am getting the same problem when using the
ThisWorkbook example.

Something I neglected to mention before. The VBA is attached to an Access
database. The subroutine is not attached to the excel file which I am trying
to save.

Restating the process with further detail... Using Access VBA, the excel
application is created. Then, the initial excel file is created and saved.
Then a second, pre-exising file is opened (within the same application) that
contains a single worsheet. This worksheet is then moved to the inital file
and the initial file is resaved. Then another pre-existing file is opened and
moved into the initial file. The save doesn't work the second time through.

Thanks,
Kevin


"Jim Jackson" wrote:

If you are talking about trying to save the original workbook add this line
just below the "Save" line.
ThisWorkbook.Activate

Or instead of ActiveWorkbook.Save use This Workbook.Save.
--
Best wishes,

Jim


"Kevin" wrote:

From VBA, I start with an excel workbook with one worksheet. Then, I open a
second excel file (with one worksheet), edit it and bring the tab into the
original workbook. So, there are now two worksheets in the original workbook.
Then save it - this works. Then, do it again... Open a new second excel file,
edit the tab and bring it into existing workbook. Now there are 3 tabs in the
original workbook. I try to save and it gives an error "document not
saved"... using the following code:

Workbooks.Open ("\\...path\Summary.xls")
Windows("Summary.xls").Activate
Sheets("Tab1").Select
Sheets("Tab1").Move befo=Workbooks(Original).Sheets(1)
ActiveWorkbook.Save


NickHK

Excel document not saving
 
Kevin,
When Automating Excel (or any app) externally, you need to be more careful.
Creating additional refereneces, to those you expect and and deal with,
becomes a problem and may prevent you from closing down the app at the end
of your code.
Thus you should always only use fully qualified refereneces to the objects
used.
Also avoid .Select/.Activate, unless it is required, which is seldom the
case. e.g.

Dim XLApp As Excel.Application
Dim XLWBSource As Excel.WorkBook
Dim XLWBDestination As Excel.WorkBook
Dim XLWS As Excel.WorkSheet

Set XLApp=New Excel.Application
Set XLWBSource=XLApp.Workbooks.Open ("\\...path\Summary.xls")
Set XLWS=XLWBSource.Worksheets(""Tab1")

Set XLWBDestination =XLApp.Workbooks.Open ("\\...path\Original.xls")

XLWS.Move befo=XLWBDestination.Sheets(1)
XLWBSource.Save

NickHK

"Kevin" wrote in message
...
Thanks for your help. I am getting the same problem when using the
ThisWorkbook example.

Something I neglected to mention before. The VBA is attached to an Access
database. The subroutine is not attached to the excel file which I am

trying
to save.

Restating the process with further detail... Using Access VBA, the excel
application is created. Then, the initial excel file is created and saved.
Then a second, pre-exising file is opened (within the same application)

that
contains a single worsheet. This worksheet is then moved to the inital

file
and the initial file is resaved. Then another pre-existing file is opened

and
moved into the initial file. The save doesn't work the second time

through.

Thanks,
Kevin


"Jim Jackson" wrote:

If you are talking about trying to save the original workbook add this

line
just below the "Save" line.
ThisWorkbook.Activate

Or instead of ActiveWorkbook.Save use This Workbook.Save.
--
Best wishes,

Jim


"Kevin" wrote:

From VBA, I start with an excel workbook with one worksheet. Then, I

open a
second excel file (with one worksheet), edit it and bring the tab into

the
original workbook. So, there are now two worksheets in the original

workbook.
Then save it - this works. Then, do it again... Open a new second

excel file,
edit the tab and bring it into existing workbook. Now there are 3 tabs

in the
original workbook. I try to save and it gives an error "document not
saved"... using the following code:

Workbooks.Open ("\\...path\Summary.xls")
Windows("Summary.xls").Activate
Sheets("Tab1").Select
Sheets("Tab1").Move befo=Workbooks(Original).Sheets(1)
ActiveWorkbook.Save





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

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