Word macro - to do some clipboard maths magic

J

John

Hi.

I would like to be able to highlight a number and then have the macro
do the following

- add 90 to it


So, for example, if I was to highlight '2' and click on the Macro
button it would return '92', overwriting the original number.


Thanks
 
J

Jean-Baptiste Bertrand

Hi !

try something like this:

Sub add_number()
Dim initial_number As Integer
Dim number_to_add As Integer
Dim final_number

initial_number = CInt(Selection.Text)
number_to_add = InputBox(prompt:="How much do you want to add ?")
final_number = initial_number + number_to_add
Selection.TypeText Text:=CStr(final_number)

end sub


Jean-Baptiste
 
J

Jean-Baptiste Bertrand

Note that if you don't want an inputbox, you can replace the
line"number_to_add = InputBox(prompt:=...." by "number_to_add = 90",
for instance
 

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