Microsoft KB Archive/290960

= Macro virus warning appears when no macros exist in the file in Word =

Article ID: 290960

Article Last Modified on 3/28/2007

-

APPLIES TO


 * Microsoft Office Word 2003
 * Microsoft Word 2002 Standard Edition
 * Microsoft Office Word 2007

-



This article was previously published under Q290960





For a Microsoft Word 2000 version of this article, see 238851.



For a Microsoft Word 97 version of this article, see 161515.



SYMPTOMS
When you open a Microsoft Word 2002 document or template, you may receive the following macro virus warning, even though the document or template does not contain macros:

'C:\ \ contains macros.

Macros may contain viruses. It is always safe to disable macros, but if the macros are legitimate, you might lose some functionality.'



CAUSE
When you delete macros from a document or template, some macro storage components are left behind. The macro virus protection feature finds this information, and the warning message may be displayed.



Microsoft Office Word 2007
To work around this problem, use one of the following methods, as appropriate for your situation.

Method 1: Delete the remaining macro storage component
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. Macros that are contained in your Word document or in your template are saved in a module. After you delete macros from a document or from a template, the module that contained the macros remains. The module is not removed when the macros are deleted. When you remove a module, the macros that it contains are deleted.

To delete the module from a Word document or from a template and to prevent the macro virus warning from appearing, follow these steps:  Open the document or the template that gives the macro virus warning. On the Developer tab, click Visual Basic in the Code group. In the Visual Basic window, expand Project  in the Project pane. The document project or the template project should resemble the following example:

Project

Note If the Project window is not visible, click Project Explorer on the View menu. To expand the document project or the template project, click the plus sign to the left of the Project . Expand the Modules folder. Click to select the module. For example, click to select  .

Note The name of the module that is listed may be different in your document project or in your template project. For example, it may be named  or a different name.</li> On the File menu, click Remove . Click No on the following message:

Do you want to export <Module Name> before removing it?

Note If you are uncertain whether the module that you are removing contains macros, click Yes. Then, export the module as a Basics (*.bas) file.</li> Repeat steps 5 and 6 for each module that is listed under the Project Modules folder.</li> On the File menu, click Close and return to Microsoft Word.</li> Save and close the Word document or the Word template.</li></ol>

The macro virus warning no longer appears when you open the document or the template.

Method 2: Copy the template to a new Word file
Note Use this procedure if the following conditions are true:
 * Your Word template contains no macros.
 * Your Word template displays the macro virus warning that is mentioned in the &quot;Symptoms&quot; section when you open the Word template or when you try to create a new document based on the template. For example, you click the Microsoft Office Button, and then you click New.

Note After the new template is created, you can copy all custom styles and AutoText entries to the new template. However, do not copy any macros to the new template. <ol> Click the Microsoft Office Button, and then click Close to close the file that displays the macro virus warning.</li> Click the Microsoft Office Button, and then click New.</li> In the Blank and recent pane, click to select Blank document, and then click Create.</li> On the Insert tab, click Object in the Text group.</li> In the Object dialog box, click Browse on the Create from File tab.</li> Change the path of the Look in box to the folder that contains the problematic template. For example, change the path of the Look in box to the following folder:

C:\Users\ \AppData\Roaming\Microsoft\Templates

Note Your template may be found in a different folder.</li> Click to select the problematic template, and then click Insert.</li> Click the Microsoft Office Button, and then click Save As.</li> In the Save As dialog box, select Document Template (*.dot) in the Save as type box.</li> In the File name box, type a name for your new template, and then click Save.</li> Click the Microsoft Office Button, and then click Close to close your new template.</li></ol>

Note Macros or remaining macro storage components from your problematic template are not saved to the new template. The macro virus warning no longer appears when you open the template or when you use it to create a new document.

Method 3: Save the Word document as a Rich Text Format (.rtf) file
Note Use this procedure when your Word document contains no macros but displays the macro virus warning that is mentioned in the &quot;Symptoms&quot; section. <ol> <li>Open the document that displays the macro virus warning.</li> <li>Click the Microsoft Office Button, and then click Save As.</li> <li>In the Save As dialog box, click Rich Text Format (*.rtf) under Save as type, and then click Save. Click Yes in the following message:

All macros in this document will be lost if the document is saved in Rich Text Format. Do you want to save in this format anyway?

</li> <li>On the File menu, click Close to close the .rtf file that you saved in step 3.</li> <li>On the File menu, click Open, and then open the .rtf file that you saved in step 3.</li> <li>On the File menu, click Save As.</li> <li>In the Save As dialog box, select Word Document (*.doc) under Save as type, and then click Save.

Note If you are saving the file back to its original file name, click Continue on the following Microsoft Office Word Compatibility Checker message:

The following features in this document are not supported by earlier versions of Word. These features may be lost or degraded when you save this document in an earlier file format. Click Continue to save the document. To keep all of your features, click Cancel, and then save the file in one of the new file formats.

Summary

Macros will be lost.

</li> <li>Close and then reopen the file.</li></ol>

Note Macros or remaining macro storage components are not saved to the new file. The macro virus warning no longer appears when you open the file.

Alternatively, run the following macro:

Option Explicit

Const stFindFolder = &quot;C:\test&quot; Sub roundtrip_wordfile_rtf 'Dim objDoc 'As Document Application.ScreenUpdating = False Dim objDocName As String Dim i   Dim FoundCnt Dim SrcFileFullName Dim objDocRtfName As String Dim objDocDocName As String Dim objDocShortName As String Dim wdApp As Object 'As Word.Application 'Object Set wdApp = CreateObject(&quot;Word.Application&quot;) wdApp.Visible = False 'Hides the application. wdApp.DisplayAlerts = wdAlertsNone 'Turns off any Dialog Boxes. With Application.FileSearch .NewSearch .Filename = &quot;*.doc&quot; .LookIn = stFindFolder .SearchSubFolders = False 'True 'Set this to True if you want to search Sub Folders. .TextOrProperty = &quot;&quot; .Execute 'The .Execute command may take a while.

FoundCnt = .FoundFiles.Count For i = 1 To FoundCnt SrcFileFullName = .FoundFiles(i) If Len(Dir(SrcFileFullName)) > 0 Then Debug.Print SrcFileFullName 'This prints out the name fo the file that was worked on in the Immediate Window. wdApp.Documents.Open (SrcFileFullName) objDocRtfName = Replace(SrcFileFullName, &quot;.doc&quot;, &quot;.rtf&quot;, 1,, vbTextCompare) 'Changes the file name to *.rtf. 'objDocShortName = Replace(objDocRtfName, stFindFolder & &quot;\&quot;, &quot;&quot;, 1,, vbTextCompare)'In case yoiu need the short file name. wdApp.Documents(SrcFileFullName).SaveAs Filename:=objDocRtfName, FileFormat:=wdFormatRTF, _ LockComments:=False, Password:=&quot;&quot;, AddToRecentFiles:=True, WritePassword _ :=&quot;&quot;, ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False wdApp.Documents.Close wdApp.Visible = False 'objDoc.Close wdApp.Documents.Open objDocRtfName objDocDocName = Replace(objDocRtfName, &quot;.rtf&quot;, &quot;.doc&quot;, 1,, vbTextCompare) 'Changes the file name to *.doc. wdApp.Documents(objDocRtfName).SaveAs Filename:=objDocDocName, FileFormat:=wdFormatRTF, _ LockComments:=False, Password:=&quot;&quot;, AddToRecentFiles:=True, WritePassword _ :=&quot;&quot;, ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False wdApp.Documents.Close wdApp.Visible = False Kill objDocRtfName 'This deletes the *.rtf file used to remove the macros. End If       Next i    End With wdApp.Quit Set wdApp = Nothing End Sub

Microsoft Word 2002
To work around this problem, use one of the following methods appropriate for your situation.

Method 1: Delete the Remaining Macro Storage Component
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. Macros that are contained in your Word document or template are saved in a module. After you delete macros from a document or template, the module that contained the macros remains and is not removed when the macros are deleted.

To delete the module from your Word document or template and prevent the macro virus warning from appearing, follow these steps.

Note Removing a module deletes the macros that it contains. <ol> <li>Open the document or template that gives the macro virus warning.</li> <li>On the Tools menu, point to Macro, and then click Visual Basic Editor.</li> <li>In the Project window, expand the document (template) project. The document (template) project should look similar to the following example:

Project

NOTE: If the Project window is not visible, click Project Explorer on the View menu.</li> <li>Expand the Modules folder.</li> <li>Click to select the module. For example, click to select NewMacros.

Note The name of the module that is listed may be different in your document (template) project. For example, it may be named Module1 or some different name.</li> <li>On the File menu, click Remove . Click No to the following message:

Do you want to export <Module Name> before removing it?

NOTE: If you are uncertain whether the module you are removing contains macros, click Yes and then export the module as a Basics Files (*.bas).</li> <li>Repeat steps 5 and 6 for each module that is listed under the Project Modules folder.</li> <li>On the File menu, click Close and return to Microsoft Word.</li> <li>Save and close the Word document (template).</li></ol>

The macro virus warning no longer appears when you open the document (template).

Method 2: Copy the Template to a New Word File
Note Use this procedure when your Word template contains no macros but displays the macro virus warning as described in the &quot;Symptoms&quot; section of this article when you open it or try to create a new document based on it (on the File menu, click New). Create a new template by following these steps.

Note After the new template is created, you can copy all custom styles, AutoText entries, and so on to the new template, but do not copy any macros to the new template. <ol> <li>On the File menu, click Close to close the file that displays the macro virus warning.</li> <li>On the File menu, click New.</li> <li>On the General tab, click to select Blank Document, and then click OK.</li> <li>On the Insert menu, click File.</li> <li>In the Insert File dialog box, change the Files of type box to Document Templates (*.dot).</li> <li>Change the Look in box to the folder that contains the problem template. For example, change the Look in box to the following folder:

C:\WINDOWS\Application Data\Microsoft\Templates

NOTE: Your template may be found in a different folder.</li> <li>Click to select the problem template, and then click Insert.</li> <li>On the File menu, click Save As.</li> <li>In the Save As dialog box, change the Save as type box to Document Template (*.dot).</li> <li>In the File name box, type a file name for your new template, and then click Save.</li> <li>On the File menu, click Close to close your new template.</li></ol>

Any macros or remaining macro storage components from your problem template are not saved to the new template. The macro virus warning no longer appears when you open the template or use it to create a new document.

Method 3: Save the Word Document as Rich Text Format (RTF)
Note Use this procedure when your Word document contains no macros but displays the macro virus warning as described in the &quot;Symptoms&quot; section. <ol> <li>Open the document that gives the macro virus warning.</li> <li>On the File menu, click Save As.</li> <li>In the Save As dialog box, under Save as type, click Rich Text Format (*.rtf), and then click Save. Click Yes to the following message:

'All macros in this document will be lost if the document is saved in Rich Text Format. Do you want to save in this format anyway?'

</li> <li>On the File menu, click Close to close the Rich Text Format document that you just saved.</li> <li>On the File menu, click Open and open the Rich Text Format document that you saved in step 3.</li> <li>On the File menu, click Save As.</li> <li>In the Save As dialog box, under Save as type, click Word Document (*.doc), and then click Save. If you are saving the file back to its original file name, click Yes to the following message:

'The file already exists. Do you want to replace the existing file?'

</li> <li>Close and reopen the document.</li></ol>

Any macros or remaining macro storage components are not saved to the new document. The macro virus warning no longer appears when you open the document.

Alternatively, run the following macro:

Option Explicit

Const stFindFolder = &quot;C:\test&quot; Sub roundtrip_wordfile_rtf 'Dim objDoc 'As Document Application.ScreenUpdating = False Dim objDocName As String Dim i   Dim FoundCnt Dim SrcFileFullName Dim objDocRtfName As String Dim objDocDocName As String Dim objDocShortName As String Dim wdApp As Object 'As Word.Application 'Object Set wdApp = CreateObject(&quot;Word.Application&quot;) wdApp.Visible = False 'Hides the application. wdApp.DisplayAlerts = wdAlertsNone 'Turns off any Dialog Boxes. With Application.FileSearch .NewSearch .Filename = &quot;*.doc&quot; .LookIn = stFindFolder .SearchSubFolders = False 'True 'Set this to True if you want to search Sub Folders. .TextOrProperty = &quot;&quot; .Execute 'The .Execute command may take a while.

FoundCnt = .FoundFiles.Count For i = 1 To FoundCnt SrcFileFullName = .FoundFiles(i) If Len(Dir(SrcFileFullName)) > 0 Then Debug.Print SrcFileFullName 'This prints out the name fo the file that was worked on in the Immediate Window. wdApp.Documents.Open (SrcFileFullName) objDocRtfName = Replace(SrcFileFullName, &quot;.doc&quot;, &quot;.rtf&quot;, 1,, vbTextCompare) 'Changes the file name to *.rtf. 'objDocShortName = Replace(objDocRtfName, stFindFolder & &quot;\&quot;, &quot;&quot;, 1,, vbTextCompare)'In case yoiu need the short file name. wdApp.Documents(SrcFileFullName).SaveAs Filename:=objDocRtfName, FileFormat:=wdFormatRTF, _ LockComments:=False, Password:=&quot;&quot;, AddToRecentFiles:=True, WritePassword _ :=&quot;&quot;, ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False wdApp.Documents.Close wdApp.Visible = False 'objDoc.Close wdApp.Documents.Open objDocRtfName objDocDocName = Replace(objDocRtfName, &quot;.rtf&quot;, &quot;.doc&quot;, 1,, vbTextCompare) 'Changes the file name to *.doc. wdApp.Documents(objDocRtfName).SaveAs Filename:=objDocDocName, FileFormat:=wdFormatRTF, _ LockComments:=False, Password:=&quot;&quot;, AddToRecentFiles:=True, WritePassword _ :=&quot;&quot;, ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False wdApp.Documents.Close wdApp.Visible = False Kill objDocRtfName 'This deletes the *.rtf file used to remove the macros. End If       Next i    End With wdApp.Quit Set wdApp = Nothing End Sub

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.

<div class="moreinformation_section">

MORE INFORMATION
Macro storage components are not present in a Word document or template until you store a macro in the file. These components exist as supporting structures for the existence and storage of macros in a file. When you delete all of the macros in a file, the macro storage components are not removed. The macro virus warning feature of Microsoft Word detects the macro storage components in the file and presents the macro virus warning when you open the file.

To remove macros from a Word document, follow these steps:

Microsoft Word 2002

 * 1) Open the file in Word.
 * 2) On the Tools menu, point to Macro, and then click Macros.
 * 3) In the Macros dialog box, select a macro name, and then click Delete. This removes the macro from the file.
 * 4) Repeat step 3 for each macro that you want to remove.

Microsoft Office Word 2007

 * 1) Open the file in Word 2007.
 * 2) On the Developer tab, click Macros in the Code group.
 * 3) In the Macros dialog box, select a macro name, and then click Delete. This removes the macro from the file.
 * 4) Repeat step 3 for each macro that you want to remove.

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

233396 How to reduce the chances of macro virus infection

Additional query words: vba WD2002 WD2007

Keywords: kbbug kbpending KB290960

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.