Variation to a Word Heretic Macro

G

Greg Maxey

Hello,

Yesterday the Word Heretic (Steve Hudson) posted a macro for killing
footnotes. I have bumbled along for the last hour or so trying to adapt his
simple code to allow the user to input what he/wants to kill. I have tried
String, Range, Long, Object and several others where the ???? appears below
and I keep getting one error code or another about type mismatch, object not
set, and on and on.

Would one of you have a look and see if you can steer me back on course?
Thanks

Sub KillAnything()
Dim myThing As ?????
Title = "Kill Box"
Message = "Type the object name of the thing you want to kill e.g., Fields,
Shapes, etc."
myThing = InputBox(Message, Title)
'Even better would be a InputBox with radio buttons listing common objects
With ActiveDocument.myThing
While .Count > 0
.Item(1).Delete
Wend
End With

End Sub
 
W

Word Heretic

G'day "Greg Maxey" <[email protected]>,

VARIANT

Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: WordHeretic at tpg.com.au


Greg Maxey was spinning this yarn:
 
P

Peter Hewett

Hi Greg

I don't know of a way to do what you want.

The code "myThing = InputBox(Message, Title)" is ALWAYS going to assign a
string to myThing, not an object of the type you are specifying in the
InputBox. Also the statement "ActiveDocument.myThing" isn't going to work
as it will expect myThing to be a Property or Method of the Document
object.

When you assign objects to a Variant, the Variant essentially just acts as
a pointer to a pre-existing object. You can't assign a non instantiated
class to a Variant.

If you could get it working you've also assumed that all objects are
Properties/Methods of the Document object. Take Cells for example, the
parent object of a Cell is always a Table.

You might be able to put something together using an extensive Case
statement.

HTH + Cheers - Peter
 
G

Greg Maxey

Peter,
You might be able to put something together using an extensive Case
statement.

Brain surgery would likely be more doable fo me :)

Thanks for the explanation. The whole point of the experiment was to learn
something and I have accomplished that regardless of the final state of the
macro. I was even reminded that Variant is a better word than Variation for
the subject.

Thanks.


--
Greg Maxey
A peer in "peer to peer" support
Rockledge, FL
To e-mail, edit out the "w...spam" in (e-mail address removed)

Peter Hewett wrote: You might be able to put something together using an
extensive Case
 
W

Word Heretic

G'day "Greg Maxey" <[email protected]>,

LOL - you are in form today.

Dim Something as Variant

Set Something = ActiveDocument
Set Something = Selection
Set Something = ...

Steve Hudson
Word Heretic Sydney Australia
Tricky stuff with Word or words

Email: WordHeretic at tpg.com.au


Greg Maxey was spinning this yarn:
 
G

Greg Maxey

Steve,

Glad I made you laugh.

I tried, but don't know enough about VBA to do anything with the hints you
have provided.

Thanks just the same.
 

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