Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Automation problem

Hello, I am exporting Access 97 data to Excel (using TransferSpreadsheet
etc). Through an Access procedure I am then formatting the data in the
exported file. The problem is that when I run the code, I come up against an
error message on the following line of code:

xlApp.ActiveWorkbook.SaveAs ("filepath")

Elsewhere in the procedure I have avoided using any reference to ActiveCells
etc and the code runs ok, but I don't know an alternative to
ActiveWorkbook.SaveAs. Could anyone please advise? Many thanks in advance...

Tim Long

I have checked that the Excel 8.0 reference is present, have checked that
the file doesn't already exist and have tried clearing every Excel process
using task manager before running the code. All to no avail.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Automation problem

It would help to know the specific error. Also, is this a workbook you
opened from a saved copy, or is it a new workbook generated by your code?
Instead of ActiveWorkbook you should be able to refer to the workbook by
name, Workboooks(BookName), as long as you know (or set) the name. If opened
from a file, it should be the file name, e.g. Workbooks("saved file.xls"); if
created in code it is normally Workbooks("Book1") for the first one created,
etc.
--
- K Dales


"Tim Long" wrote:

Hello, I am exporting Access 97 data to Excel (using TransferSpreadsheet
etc). Through an Access procedure I am then formatting the data in the
exported file. The problem is that when I run the code, I come up against an
error message on the following line of code:

xlApp.ActiveWorkbook.SaveAs ("filepath")

Elsewhere in the procedure I have avoided using any reference to ActiveCells
etc and the code runs ok, but I don't know an alternative to
ActiveWorkbook.SaveAs. Could anyone please advise? Many thanks in advance...

Tim Long

I have checked that the Excel 8.0 reference is present, have checked that
the file doesn't already exist and have tried clearing every Excel process
using task manager before running the code. All to no avail.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Automation problem

Hello, the code in question is:

Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Add
xlApp.ActiveWorkbook.SaveAs "F:\Test_05_07_20.xls"
xlApp.ActiveWorkbook.Close
Set xlApp = Nothing

Later in the Access procedure, the Access data is exported to the
newly-created spreadsheet.

I have been getting a variety of errors. The latest one is Run-time error:
1004 The file could not be accessed. However, so far as I can see, there's no
problem with the file name, filename length, folder etc...

"K Dales" wrote:

It would help to know the specific error. Also, is this a workbook you
opened from a saved copy, or is it a new workbook generated by your code?
Instead of ActiveWorkbook you should be able to refer to the workbook by
name, Workboooks(BookName), as long as you know (or set) the name. If opened
from a file, it should be the file name, e.g. Workbooks("saved file.xls"); if
created in code it is normally Workbooks("Book1") for the first one created,
etc.
--
- K Dales


"Tim Long" wrote:

Hello, I am exporting Access 97 data to Excel (using TransferSpreadsheet
etc). Through an Access procedure I am then formatting the data in the
exported file. The problem is that when I run the code, I come up against an
error message on the following line of code:

xlApp.ActiveWorkbook.SaveAs ("filepath")

Elsewhere in the procedure I have avoided using any reference to ActiveCells
etc and the code runs ok, but I don't know an alternative to
ActiveWorkbook.SaveAs. Could anyone please advise? Many thanks in advance...

Tim Long

I have checked that the Excel 8.0 reference is present, have checked that
the file doesn't already exist and have tried clearing every Excel process
using task manager before running the code. All to no avail.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default Automation problem

I have done a lot of Excel automation through Access - this is how I usually
handle similar situations:
Dim xlApp as Excel.Application
Dim xlBook as Excel.Workbook
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add()
xlBook.SaveAs "F:\Test_05_07_20.xls"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing

As to the errors: I don't think they have to do with using ActiveWorkbook
(though I always prefer to refer to objects explicitly anyway, so I think the
above way of referencing the book is better). For one thing, you are not
getting consistent error messages - which implies that the condition
triggering the error is different each time. Also, the error you mention
would have nothing to do with how the workbook was referenced; it points to a
problem with file access. I do believe you when you say you have checked
this but that is still a least the error that Excel sees. I don't know why
that might be, the only thought I have is that timing might be an issue.
Perhaps for some reason the drive is not ready when you are trying to save
the book.
--
- K Dales


"Tim Long" wrote:

Hello, the code in question is:

Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Add
xlApp.ActiveWorkbook.SaveAs "F:\Test_05_07_20.xls"
xlApp.ActiveWorkbook.Close
Set xlApp = Nothing

Later in the Access procedure, the Access data is exported to the
newly-created spreadsheet.

I have been getting a variety of errors. The latest one is Run-time error:
1004 The file could not be accessed. However, so far as I can see, there's no
problem with the file name, filename length, folder etc...

"K Dales" wrote:

It would help to know the specific error. Also, is this a workbook you
opened from a saved copy, or is it a new workbook generated by your code?
Instead of ActiveWorkbook you should be able to refer to the workbook by
name, Workboooks(BookName), as long as you know (or set) the name. If opened
from a file, it should be the file name, e.g. Workbooks("saved file.xls"); if
created in code it is normally Workbooks("Book1") for the first one created,
etc.
--
- K Dales


"Tim Long" wrote:

Hello, I am exporting Access 97 data to Excel (using TransferSpreadsheet
etc). Through an Access procedure I am then formatting the data in the
exported file. The problem is that when I run the code, I come up against an
error message on the following line of code:

xlApp.ActiveWorkbook.SaveAs ("filepath")

Elsewhere in the procedure I have avoided using any reference to ActiveCells
etc and the code runs ok, but I don't know an alternative to
ActiveWorkbook.SaveAs. Could anyone please advise? Many thanks in advance...

Tim Long

I have checked that the Excel 8.0 reference is present, have checked that
the file doesn't already exist and have tried clearing every Excel process
using task manager before running the code. All to no avail.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Automation problem

Sorted! Many thanks!

"K Dales" wrote:

I have done a lot of Excel automation through Access - this is how I usually
handle similar situations:
Dim xlApp as Excel.Application
Dim xlBook as Excel.Workbook
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add()
xlBook.SaveAs "F:\Test_05_07_20.xls"
xlBook.Close
xlApp.Quit
Set xlBook = Nothing
Set xlApp = Nothing

As to the errors: I don't think they have to do with using ActiveWorkbook
(though I always prefer to refer to objects explicitly anyway, so I think the
above way of referencing the book is better). For one thing, you are not
getting consistent error messages - which implies that the condition
triggering the error is different each time. Also, the error you mention
would have nothing to do with how the workbook was referenced; it points to a
problem with file access. I do believe you when you say you have checked
this but that is still a least the error that Excel sees. I don't know why
that might be, the only thought I have is that timing might be an issue.
Perhaps for some reason the drive is not ready when you are trying to save
the book.
--
- K Dales


"Tim Long" wrote:

Hello, the code in question is:

Set xlApp = CreateObject("Excel.Application")
xlApp.Workbooks.Add
xlApp.ActiveWorkbook.SaveAs "F:\Test_05_07_20.xls"
xlApp.ActiveWorkbook.Close
Set xlApp = Nothing

Later in the Access procedure, the Access data is exported to the
newly-created spreadsheet.

I have been getting a variety of errors. The latest one is Run-time error:
1004 The file could not be accessed. However, so far as I can see, there's no
problem with the file name, filename length, folder etc...

"K Dales" wrote:

It would help to know the specific error. Also, is this a workbook you
opened from a saved copy, or is it a new workbook generated by your code?
Instead of ActiveWorkbook you should be able to refer to the workbook by
name, Workboooks(BookName), as long as you know (or set) the name. If opened
from a file, it should be the file name, e.g. Workbooks("saved file.xls"); if
created in code it is normally Workbooks("Book1") for the first one created,
etc.
--
- K Dales


"Tim Long" wrote:

Hello, I am exporting Access 97 data to Excel (using TransferSpreadsheet
etc). Through an Access procedure I am then formatting the data in the
exported file. The problem is that when I run the code, I come up against an
error message on the following line of code:

xlApp.ActiveWorkbook.SaveAs ("filepath")

Elsewhere in the procedure I have avoided using any reference to ActiveCells
etc and the code runs ok, but I don't know an alternative to
ActiveWorkbook.SaveAs. Could anyone please advise? Many thanks in advance...

Tim Long

I have checked that the Excel 8.0 reference is present, have checked that
the file doesn't already exist and have tried clearing every Excel process
using task manager before running the code. All to no avail.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Automation problem

In automation, I would avoid using Activeworkbook (in fact, it is best to
avoid it without automation <g) by setting a workbook object when you open
the file or create it

Something like

xlWB = xlApp.Workbooks.Open "myFile.xls"

or

xlWB = xlApp.Worksbooks.Add

That way you always have a handle to that workbook.

Thenn when saving, just use

xlWB..SaveAs "filepath"


--
HTH

Bob Phillips

"Tim Long" wrote in message
...
Hello, I am exporting Access 97 data to Excel (using TransferSpreadsheet
etc). Through an Access procedure I am then formatting the data in the
exported file. The problem is that when I run the code, I come up against

an
error message on the following line of code:

xlApp.ActiveWorkbook.SaveAs ("filepath")

Elsewhere in the procedure I have avoided using any reference to

ActiveCells
etc and the code runs ok, but I don't know an alternative to
ActiveWorkbook.SaveAs. Could anyone please advise? Many thanks in

advance...

Tim Long

I have checked that the Excel 8.0 reference is present, have checked that
the file doesn't already exist and have tried clearing every Excel process
using task manager before running the code. All to no avail.



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
Excel 2003 c++ automation problem. Ken Excel Worksheet Functions 0 January 9th 07 12:13 AM
May be Automation AddIn loading problem!! Abhijit Excel Programming 0 June 6th 05 06:45 PM
Problem in graph automation in excel. news.microsoft.com[_7_] Excel Programming 3 April 30th 05 06:02 AM
Automation Add-in Distribution problem kumar_8675[_4_] Excel Programming 1 November 5th 04 02:09 AM
TypeConverter Excel-Automation problem Markus Excel Programming 0 August 23rd 04 11:17 AM


All times are GMT +1. The time now is 02:05 AM.

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

About Us

"It's about Microsoft Excel"