Code to delete footnotes

G

Grant

Hello,

I created the following word macro in VBA to go through the current folder
opening up all word documents and deleting the footnotes from them. Footnote
text and numbers are deleted but when I go back into the document and click
on 'View', I can still select footnotes - which means there are still
footnote references so they havent been completely deleted. When I view the
footnotes section - there is no text BUT threre are full stop characters
with 'Footnote Text' formatting, which I dont know how to get rid of??? The
wierd thing is that before in the main document text there were numbers to
indicate footnotes but they have all been deleted - but if I select one of
the full stops in the footnote section, the main document jumps to a certain
point - but there is no footnote number there, its as if though the number
has been replaced by one of the text characters.

Can anyone show me why my code didnt completely delete the footnotes? The
only other way I know iof doing it is to open each document and do a search
and replace manually, which would take ages.

-----------------------------------------------
Sub DeleteFootnotes()
Dim strDirName
Dim strFileName
Dim intFootnoteCounter As Integer
Dim objFileSystem
Dim objFolder
Dim objDocument As Document

strDirName = ActiveDocument.Path & "\"

Set objFileSystem = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSystem.GetFolder(strDirName)

'Iterate through the files in the folder
For Each objFile In objFolder.Files

Set objDocument = Documents.Open(strDirName + objFile.Name)

For Each objFootNote In objDocument.Footnotes
objFootNote.Delete
Next objFootNote

objDocument.Save
objDocument.Close

Next objFile

MsgBox ("Footnotes deleted,.. well.. maybe")
End Sub
 
D

Doug Robbins - Word MVP

Hi Grant,

You need to delete the footnote reference as well:

For Each objFootNote In objDocument.Footnotes
objFootNote.Delete
objFootnote.Reference.Delete
Next objFootNote

In fact, I'm pretty sure that if you just delete the .Reference, the
footnote will go along with it, so all you would need is

For Each objFootNote In objDocument.Footnotes
objFootNote.Reference.Delete
Next objFootNote


--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
P

Peter Hewett

Hi Grant

I've tried reproducing this problem using Word XP and I have not been able to do
so. When I iterate the Footnotes collection all footnotes are deleted. If I
save/open the document the View>Footnotes option is disabled.

Try doing it from with the Word VBA IDE and see if you can reproduce the
problem. Just write a small sub that deletes the footnotes and see if the
problem remains.

HTH + Cheers - Peter
 
G

Grant

Thanks for the quick reply! the document I am left with has had all the
references deleted but there is still something remaining. When I run the
sub the error is "Object has been deleted" but I can still see the footnotes
section with these full stops that link to certain text sections.

I ran this over the backup document (which still has the reference numbers)
using 'objFootnote.Reference.Delete' method, and it succesfully got rid of
everything. I cant see any footnotes anymore.

Thanks for your help,
Cheers,
Grant
 

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