Solved

Help with arguments for Excel.Workbook.SaveAs function

Posted on 2006-06-30
2
698 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VBScript - Find file starting with XXXX use that in runnig rest of code 9 78
Convert VB6 MSXML2.ServerXMLHTTP process to C# 2 47
Child Form in front 4 47
Advice in Xamarin 21 79
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

773 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