Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8015615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:18:10+00:00 2026-06-04T20:18:10+00:00

I have an application that dynamically insert VBA code to help building a MS

  • 0

I have an application that dynamically insert VBA code to help building a MS word document with proper bookmarks. The VBA code doesn’t need to be saved with the document itself.

When saving the document, the following warning (unfortunately I can’t post an image yet) will pop up that confuses the end users of the application. Is there a way to disable this within the DocumentBeforeSave event?

**

The following cannot be saved in a macro-free document: VBA project To
save a file with these features, click No to return to the Save As
dialog, and then choose a macro-enabled file type in the File Type
drop-down. Continue saving as a macro-free document?
buttons: [Yes][No][Help]

**

One idea is to change the document’s SaveFormat to an older format in order to prevent this warning from popping up. But I’m not sure if this change will affect how the document behaves going forward and if it’s even possible to modify this property within the DocumentBeforeSave event (the property is a READONLY property).

Thanks in advance for any help on this topic.

The following code will open a word (assuming c:\work\test.docx exist, which can be just a blank word doc). If you hit the Save button on the word doc, the warning message will show up. BTW, I’m using Office 2010.

<TestMethod()>
Public Sub testWord()
    Dim wApp As New Word.Application()
    Dim myDoc As Word.Document
    Dim DataCodeModule As Object = Nothing

    myDoc = wApp.Documents.Open("C:\Work\test.docx")

    DataCodeModule = myDoc.VBProject.VBComponents(0).CodeModule
    With DataCodeModule
        .InsertLines(1, "Option Explicit")
        .InsertLines(2, "Sub TestCode()")
        .InsertLines(3, "Selection.InsertAfter ""test""")
        .InsertLines(4, "End Sub")
    End With

    wApp.Visible = True
    myDoc.Activate()
End Sub

And once the DocumentBeforeSave is hooked up, I was hoping the following code would disable the warning. Maybe the DisplayAlerts need to be set as soon as the document is opened?

Public Sub App_DocumentBeforeSave(ByVal doc As Object, ByRef saveAsUI As Boolean, ByRef cancel As Boolean) Handles _officeHelper.DocumentBeforeSave
            Dim WordApp As Object = this.WordApp()
            'WordApp.DisplayAlerts = False
            WordApp.DisplayAlerts = 0
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T20:18:13+00:00Added an answer on June 4, 2026 at 8:18 pm

    Like this?

    Application.DisplayAlerts = wdAlertsNone
    '~~> Your Save Code
    Application.DisplayAlerts = wdAlertsAll
    

    FOLLOWUP

    You are doing it in vb.net. I don’t have access to VB.net at the moment but this example below will set you on the right path

    Open Word and insert a module and then paste this code

    Option Explicit
    
    Dim MyClass As New Class1
    
    Sub Sample()
        Set MyClass.App = Word.Application
    End Sub
    

    Now insert a Class Module and paste this code

    Public WithEvents App As Word.Application
    
    Private Sub App_DocumentBeforeSave(ByVal Doc As Document, _
    SaveAsUI As Boolean, Cancel As Boolean)
    
        Application.DisplayAlerts = wdAlertsNone
        ActiveDocument.Save
        Application.DisplayAlerts = wdAlertsAll
    
    End Sub
    

    Now if you press the save button, you will notice that you won’t get that alert any more. 🙂

    Hope you can adapt it as required 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that compiles some code dynamically, and creates an assembly as
I have a pretty large application that dynamically loads shared objects and executes code
I have a web application that dynamically loads assemblies based on database configuration entries
I have a .Net application that dynamically creates a small HTML page and pops
I have a Winforms application that dynamically instantiates external form objects for use in
I have a control bar on my application that has popovers with dynamically loaded
I have two application that need to talk to each other. App1 needs to
I have a web application that dynamically creates a web page using usercontrols. Within
I have an application in turbogears that dynamically generates an excel spreadsheet, meaning it
I have created an MVC application that dynamically routes actions and controllers based on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.