IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Programmatically stripping VBA from a document?
I have a word document that has a solitary macro included. So that we don't offend the users on the other end, (by presenting them with the "This document has a macro" message) I would like the macro to politely self-destruct on execution, as it is a one-time macro.

Is there functionality such as this contained in VBA, or am I pipe dreaming?
The universe makes no sense until you accept that God uses base 13.

Even then, it's still pretty dodgy.
New No clue, but...
You can define a macro in one document that works on another document. Then the document that you send users can have the macro run, but never had that macro installed so they won't trip the issue.

Ben
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New Re: No clue, but...
Are you sure of that? I would think that any document that tries to do any macro would raise the warning. If what you say is true, then that is the most balled up "feature" I can think of.
-drl
New The goal is only to avoid annoying the users
Annoying yourself is acceptable.

Also I haven't used Windows enough recently to know where the warning is coming from. My guess is that Outlook is doing it as an anti-virus feature. So running the program wouldn't generate a warning. I could trivially be wrong on that. But I would be surprised if the warning was something that you couldn't choose to silence on your machine...

Ben
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
New CodeModule
Look at the CodeModule Object. I then found the following on the net by searching for vba codemodule delete word. No idea if it works:
\n\nSub Remove(ByVal MacroName As String)\n    Dim vbc As VBComponent\n    Dim MyMacro As String\n\n    Set vbc = VBE.ActiveVBProject.VBComponents("ThisDocument")\n    With vbc.CodeModule\n        .DeleteLines .ProcStartLine(MacroName, vbext_pk_Proc), _\n            .ProcCountLines(MacroName, vbext_pk_Proc)\n    End With\n\nEnd Sub\n

--
Chris Altmann
New Some ways to do it
One way is to take the macro out of your Autoexec Startup for the document. Usually the error doesn't happen until a macro is run IIRC. Of course my experience is only with Office 2000 and previous versions, so I don't know how newer versions handle that.

One quick way is to save the document as RTF and then load it and save it as a Doc file. Just hope that you don't lose any important formatting. Save it as a different name and see if it strips out the macro, I am sure it will. I am not sure how it will handle tables, bookmarks, and other Word features. Another way may be to use OpenOffice.Org as I think it does strip out macros as it doesn't use them, but don't quote me on that.

Even if you have a self destructing macro, the user will still get the "This document has a macro" error. They will get it only once and after they run the macro it should clean itself off.

What you want is almost the reverse of a Macro Virus, you have a Macro that kills itself.

I found this self-modifying code:
[link|http://chrisrae.com/vba/routines/selfmodify.html|http://chrisrae.com/...s/selfmodify.html]

I am sure that you can use it in reverse to delete lines. Look up the "Application.VBE.ActiveVBProject.VBComponents" object.

Ah yes, I think I found it:
[link|http://www.excel-center.com/mailing/067699h.htm|http://www.excel-cen...iling/067699h.htm]

'Place the code below into the standard module
Sub ModuleClear()
MsgBox "I am not there!"
With Application.VBE.ActiveVBProject
.vbComponents.Remove .vbComponents("MyModule")
End With
End Sub

Just put in the name of your module in the "MyModule" place and it should work. Maybe remove the Msgbox as it doesn't really serve a purpose.

I know the example is for Excel, but I think the VBE object also exists in Word.



"Lady I only speak two languages, English and Bad English!" - Corbin Dallas "The Fifth Element"

Expand Edited by orion Nov. 11, 2003, 04:09:36 PM EST
New And this is why I never filtered you. (new thread)
Created as new thread #125182 titled [link|/forums/render/content/show?contentid=125182|And this is why I never filtered you.]
The universe makes no sense until you accept that God uses base 13.

Even then, it's still pretty dodgy.
New RTF Conversion.
I don't know about Word 2000 and newer, but in Word 97, RTF-save didn't support any custom UI elements (menubars, keybindings, etc), macros or form-mode. Everything else saved and loaded a-okay. I had Word 97 default to RTF format for quite a while.

Wade.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

New Boy, was *that* not what I expected
I read your subject line as "RTF Conversation". And of course mentally converted "RTF" to the other well known acronym. Was wondering, "Geez, why is Wade going off on Norm?"
===

Implicitly condoning stupidity since 2001.
New You're working too hard.


Peter
[link|http://www.debian.org|Shill For Hire]
[link|http://www.kuro5hin.org|There is no K5 Cabal]
[link|http://guildenstern.dyndns.org|Blog]
New Nope, thought the same too...
"All men are like grass, and all their glory is like the flowers of the field;
the grass withers and the flowers fall, but the word of the Lord stands forever."
1 Peter 1:24-25
New I had done a "double take" to get it right.
Alex

"The illegal we do immediately. The unconstitutional takes a little longer." - Henry Kissinger
New LOL.

Is it enough to love
Is it enough to breathe
Somebody rip my heart out
And leave me here to bleed
 
Is it enough to die
Somebody save my life
I'd rather be Anything but Ordinary
Please

-- "Anything but Ordinary" by Avril Lavigne.

     Programmatically stripping VBA from a document? - (inthane-chan) - (12)
         No clue, but... - (ben_tilly) - (2)
             Re: No clue, but... - (deSitter) - (1)
                 The goal is only to avoid annoying the users - (ben_tilly)
         CodeModule - (altmann)
         Some ways to do it - (orion) - (7)
             And this is why I never filtered you. (new thread) - (inthane-chan)
             RTF Conversion. - (static) - (5)
                 Boy, was *that* not what I expected - (drewk) - (4)
                     You're working too hard. -NT - (pwhysall) - (1)
                         Nope, thought the same too... -NT - (jbrabeck)
                     I had done a "double take" to get it right. -NT - (a6l6e6x)
                     LOL. -NT - (static)

Where is a super volcano when you need one?
65 ms