Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default SaveAs problem in Excel VBA script

Hi

I have the following macro to save the Index sheet as a new workbook "abc"
in csv format. Since I have the abc.csv file in the c:\ directory, Excel
will ask me whether I want to overwrite the file. So I have the
application.sendkeys to say Yes to overwrite. This works fine if I am
running it manually but the macro stops at the overwrite question if I
scheduled the macro to run. Then I have to hit yes and the macro finishes it
up. Do you know how I can fix this issue? Thank you in advance.

Joanne

Sheets("Index").Select
Sheets("Index").Copy

Application.SendKeys ("Y~")

ActiveWorkbook.SaveAs Filename:="c:\abc.csv", _
FileFormat:=xlCSV, CreateBackup:=False

ActiveWindow.Close
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default SaveAs problem in Excel VBA script

Put application.displayalerts = false before the saveas line and
application.displayalerts = true after the line.

Cliff Edwards

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default SaveAs problem in Excel VBA script

Since you're closing the new workbook, return displayalerts to true
after that action.

Sub copySheet()
Sheets("Index").Copy

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\abc.csv", _
FileFormat:=xlCSV, CreateBackup:=False
ActiveWindow.Close
Application.DisplayAlerts = True

End Sub

Cliff Edwards


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default SaveAs problem in Excel VBA script

Hi Cliff,

That works... thank you very much.

Joanne



"ward376" wrote:

Since you're closing the new workbook, return displayalerts to true
after that action.

Sub copySheet()
Sheets("Index").Copy

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:="C:\abc.csv", _
FileFormat:=xlCSV, CreateBackup:=False
ActiveWindow.Close
Application.DisplayAlerts = True

End Sub

Cliff Edwards



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
Script problem on excel spanish version Giulio Excel Programming 1 July 26th 07 02:01 PM
Problem with Excel VBA script, decimal bug Richard RE Excel Programming 1 June 22nd 06 09:52 AM
problem with SaveAs method of excel in IIS 5 Ayoung Chueng Excel Programming 0 March 20th 06 03:48 AM
Problem with printing from VB-script in Excel Jo Segers Excel Programming 2 January 28th 05 07:25 AM
Weird Problem: Excel SaveAs-- document not saved Matias[_2_] Excel Programming 1 December 6th 04 06:05 PM


All times are GMT +1. The time now is 05:16 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"