Results 1 to 5 of 5

Thread: [RESOLVED] Overwriting files

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Resolved [RESOLVED] Overwriting files

    Ok, I am using oWorkBook.SaveAs to tell Excel to save a workbook. The file already exists, since I had to open it to make the changes in the first place, and I want to always overwrite the file when I'm done. Is there any way to either supress the overwrite prompt or tell it to yes always overwrite from inside the program? If I have to click yes on that prompt after every single transaction I process it will be a pain.

    And before you ask, yes, I need to save it after each one, because it pulls the information that goes into the sheets off a form that is changed from one transaction to the next.

    If you need to see the code, let me know.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Overwriting files

    You can do it either way...
    VB Code:
    1. Application.DisplayAlerts = False
    2. Application.Workbooks("Book1.xls").Save
    3. Application.Workbooks("Book1.xls").Saved = True
    4. Application.Workbooks("Book1.xls").Close
    5. Application.DisplayAlerts = True
    6. 'Or
    7. Application.DisplayAlerts = False
    8. Application.Workbooks("Book1.xls").Close SaveChanges:=True, Filename:="C:\Book1.xls"
    9. Application.DisplayAlerts = True
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: Overwriting files

    I ended up doing it this way and it works fine:

    VB Code:
    1. Application.DisplayAlerts = False ' turn off overwrite prompt
    2.             oBook.SaveAs ("C:\FHR\StableBankAccounts.xls")
    3.             Application.DisplayAlerts = True

    I'm using SaveAs so it will stay compatibel with Execl 97 (this is being done in Excel 2000).

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [RESOLVED] Overwriting files

    You need to verify that your book is getting the updates applied because when turning of displayalerts it accepts the defaults on the supressed message box. The "No" is the default.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2002
    Location
    southwest VA
    Posts
    136

    Re: [RESOLVED] Overwriting files

    Oh, I did. I loaded the sheet into Excel 97 and verified that the right stuff was put in the right cells, and it's all working fine. I'm really pleased with how this project is coming along.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width