Macro warning with no macros

C

clemensma

I know this question as been asked many times in the past and I have
searched for a fix for my situation but haven't found one that works.
Here's what's happening:

I have a workbook that does have lots of macros and is an XLSM file.
One of the macros copies one of the worksheets (doesn't have any
macros) to a new workbook. It then updates the data in the new
workbook and finally saves it using an "XLS" prefix. When I open the
new workbook I get the macro warning. I tried the following code
before the save to get rid of any macros in the new workbook and while
it does find 2 VBE component it doesn't get rid of the macro warning.

With ActiveWorkbook.VBProject
For i = .VBComponents.Count To 1 Step -1
.VBComponents(i).CodeModule.DeleteLines
1, .VBComponents(i).CodeModule.CountOfLines
Next i

For i = .VBComponents.Count To 1 Step -1
.VBComponents.Remove .VBComponents(i)
Next i
End With

Is there anything else I can do to get rid of the macro warning from
the new workbook? I know I could create a new workbook instead of
coping the sheet but I'd like to preserve all of the formatting,
headers and trailers without having to add setting them in the macro.

Thanks for your help.
 
J

James Ravenswood

I know this question as been asked many times in the past and I have
searched for a fix for my situation but haven't found one that works.
Here's what's happening:

I have a workbook that does have lots of macros and is an XLSM file.
One of the macros copies one of the worksheets (doesn't have any
macros) to a new workbook.  It then updates the data in the new
workbook and finally saves it using an "XLS" prefix.  When I open the
new workbook I get the macro warning.  I tried the following code
before the save to get rid of any macros in the new workbook and while
it does find 2 VBE component it doesn't get rid of the macro warning.

    With ActiveWorkbook.VBProject
        For i = .VBComponents.Count To 1 Step -1
            .VBComponents(i).CodeModule.DeleteLines
1, .VBComponents(i).CodeModule.CountOfLines
        Next i

        For i = .VBComponents.Count To 1 Step -1
            .VBComponents.Remove .VBComponents(i)
        Next i
    End With

Is there anything else I can do to get rid of the macro warning from
the new workbook?  I know I could create a new workbook instead of
coping the sheet but I'd like to preserve all of the formatting,
headers and trailers without having to add setting them in the macro.

Thanks for your help.

After running your posted code, verify:

1. all the subs are gone
2. all the modules that contained the subs are gone
3. all worksheet code is gone
4. all workbook code is gone

The problem is probably in the 2
 
C

clemensma

After running your posted code, verify:

1. all the subs are gone
2. all the modules that contained the subs are gone
3. all worksheet code is gone
4. all workbook code is gone

The problem is probably in the 2

Thanks for the suggestion. I had already checked all of those areas
and I don't see any code. There aren't any module files and there's
no visible code in either the worksheet or workbook.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top