Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Help with arguments for Excel.Workbook.SaveAs function

Posted on 2006-06-30
2
710 Views
Last Modified: 2008-01-09
Hello gurus,

I am trying to add a line to a VB function in Access. The function actually builds an excel spreadsheet. I want to overwrite an existing excel file with the newly built one everytime the script is run. I just can't get excel to stop prompting me about overwriting an exsiting file. Is there an argument to the SaveAs method that can turn off prompting?

My current code is:

    directory = "H:\Daily Numbers\" & Year(Now()) & "\" & MonthName(Month(Now())) & " " & Year(Now())
    ChDir (directory)
    ActiveWorkbook.SaveAs FileName:= _
        directory & "\Monthly Reporting " & MonthName(Month(Now())) & " " & Year(Now()) & "_DB.xls", _
        FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False


Thanks in advance.
0
Comment
Question by:gdrnec
2 Comments
 
LVL 5

Accepted Solution

by:
lunchbyte earned 250 total points
ID: 17020601
Try this

if dir(directory & "\Monthly Reporting " & MonthName(Month(Now())) & " " & Year(Now()) & "_DB.xls") <> "" then kill directory & "\Monthly Reporting " & MonthName(Month(Now())) & " " & Year(Now()) & "_DB.xls"

    ActiveWorkbook.SaveAs FileName:= _
        directory & "\Monthly Reporting " & MonthName(Month(Now())) & " " & Year(Now()) & "_DB.xls", _
        FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False

0
 
LVL 4

Author Comment

by:gdrnec
ID: 17020614
I'll have to test it later. I don't know why I didn't think of removing the file first.
Thanks
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question