Solved

Help with arguments for Excel.Workbook.SaveAs function

Posted on 2006-06-30
2
723 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
[X]
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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

729 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