From: John on 22 Mar 2010 07:29 Hi. I am very new to this. I'd be really grateful if someone could help/guide me. I want to create a macro in Microsoft Word but I don't know visual basic. I want to be able to highlight a number then: - copy it to the clipboard - subtract 298 - paste the value to the Word document, overwriting the original text
From: Pesach Shelniitz on 22 Mar 2010 08:06 Hi John, There is no need to involve the clipboard if you are only changing the selected number. The following macro subtracts 298 from the selected number. Sub Subtract298() If IsNumeric(Selection.Text) Then Selection.Text = Val(Selection.Text) - 298 Else MsgBox "The selected text is not a number." End If End Sub Hope this helps, Pesach Shelnitz My Web site: http://makeofficework.com "John" <helpme.code(a)yahoo.com> ??? ??????:99a5ec97-1ee9-4d8c-904e-e14513f256e9(a)q16g2000yqq.googlegroups.com... > Hi. > > I am very new to this. > > I'd be really grateful if someone could help/guide me. I want to > create a macro in Microsoft Word but I don't know visual basic. > > > I want to be able to highlight a number then: > > - copy it to the clipboard > - subtract 298 > - paste the value to the Word document, overwriting the original text
From: Greg Maxey on 22 Mar 2010 08:09 John, If the number is already highlighted in the document, then you don't need to copy it to the clipboard: Sub ScratchMaco() If IsNumeric(Selection.Text) Then Selection.Text = Selection.Text - 298 End If End Sub If there is some reason you have to put it in the clipboard, you could try: Sub ScratchMacoII() Dim myCopy As DataObject Dim myPaste As DataObject 'Must have a reference to Microsoft Forms 2.0 Object Library enabled Dim myRng As Range If IsNumeric(Selection.Text) Then Set myCopy = New DataObject myCopy.SetText Selection.Text - 298 myCopy.PutInClipboard Set myPaste = New DataObject myPaste.GetFromClipboard Selection.Text = myPaste.GetText(1) End If End Sub John wrote: > Hi. > > I am very new to this. > > I'd be really grateful if someone could help/guide me. I want to > create a macro in Microsoft Word but I don't know visual basic. > > > I want to be able to highlight a number then: > > - copy it to the clipboard > - subtract 298 > - paste the value to the Word document, overwriting the original text
From: John on 22 Mar 2010 08:40 On Mar 22, 12:06 pm, "Pesach Shelniitz" <pesac...(a)hotmail.com> wrote: > Hi John, > > There is no need to involve the clipboard if you are only changing the > selected number. The following macro subtracts 298 from the selected number. > > Sub Subtract298() > If IsNumeric(Selection.Text) Then > Selection.Text = Val(Selection.Text) - 298 > Else > MsgBox "The selected text is not a number." > End If > End Sub > > Hope this helps, > Pesach Shelnitz > My Web site:http://makeofficework.com > > "John" <helpme.c...(a)yahoo.com> ??? > ??????:99a5ec97-1ee9-4d8c-904e-e14513f25...(a)q16g2000yqq.googlegroups.com.... > > > Hi. > > > I am very new to this. > > > I'd be really grateful if someone could help/guide me. I want to > > create a macro in Microsoft Word but I don't know visual basic. > > > I want to be able to highlight a number then: > > > - copy it to the clipboard > > - subtract 298 > > - paste the value to the Word document, overwriting the original text Wow, thank you so much. It worked! :-)
|
Pages: 1 Prev: W2003: find cursor location in table coordinates (table/row/co Next: from vba to vsto |