Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2011, 12:53 PM
ACA ACA is offline Calling for an action when typing a character Windows 7 Calling for an action when typing a character Office 2007
Advanced Beginner
Calling for an action when typing a character
 
Join Date: Aug 2010
Posts: 31
ACA is on a distinguished road
Default Calling for an action when typing a character


I need for a certain macro (which I have already written) to be called and executed each time I enter a space while typing my WORD document, i.e. when I press the spacebar.
I guess what I need is another previous macro, or a line of code somewhere.

In EXCEL, I suppose, it could be some code for Worksheet_Change(ByVal Target As Range) beginning with “IF… then”. But in WORD?

Thanks for any help
ACA
Reply With Quote
  #2  
Old 06-14-2011, 04:49 PM
macropod's Avatar
macropod macropod is offline Calling for an action when typing a character Windows 7 32bit Calling for an action when typing a character Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi ACA,

Word has no 'space' event from which to trigger such a macro. If you describe what you're trying to achieve, perhaps another approach can be suggested.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-15-2011, 12:32 AM
ACA ACA is offline Calling for an action when typing a character Windows 7 Calling for an action when typing a character Office 2007
Advanced Beginner
Calling for an action when typing a character
 
Join Date: Aug 2010
Posts: 31
ACA is on a distinguished road
Default

Thank you, Paul. What I’m trying to achieve is this:
That, while I’m typing my text in Word, an existing macro be called and executed each time I type in a given character as part of the text itself.
If that is not possible in WORD (as it would be in EXCEL), I cannot think of another approach, for I know very little about the resources of VBA for WORD. But perhaps you yourself, knowing what those resources are, could suggest another possible way to achieve what I just explained I need. Would you be so kind?
In any case, thanks very much for replying and for your help so far.
ACA
Reply With Quote
  #4  
Old 06-15-2011, 07:10 AM
ACA ACA is offline Calling for an action when typing a character Windows 7 Calling for an action when typing a character Office 2007
Advanced Beginner
Calling for an action when typing a character
 
Join Date: Aug 2010
Posts: 31
ACA is on a distinguished road
Default

Another hint:
For my purpose it will also do if the macro is called
-not necessarily by the entering of a given character,
-but also if it is triggered by some other event which is part of my typing in the text document in WORD,
-like, say, every nth word entered, or every nth keystroke.
Does that suggest any new possibilites?
Thanks for just considering, anyway.
ACA
Reply With Quote
  #5  
Old 06-15-2011, 05:35 PM
macropod's Avatar
macropod macropod is offline Calling for an action when typing a character Windows 7 32bit Calling for an action when typing a character Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi ACA,

It's still not clear what you're trying to achieve (ie what is the macro supposed to do). Depending on what your goal is, it might be achievable via Word's Autotext facility. You don't need any vba for this. Word's Autotext facility allows you to type a string and Word will automatically replace that with another string (which could be a whole page of text, for example) and/or graphics. See Word's help file for details.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 06-16-2011, 04:19 AM
ACA ACA is offline Calling for an action when typing a character Windows 7 Calling for an action when typing a character Office 2007
Advanced Beginner
Calling for an action when typing a character
 
Join Date: Aug 2010
Posts: 31
ACA is on a distinguished road
Default

Thank you Paul.
No, it’s not something Word’s AutoText can do. It’s this:
I do translations. For that I keep two Word documents open, Doc.1 (on which I type my translation) and Doc.2 (with the original). My macro does this:
- It goes to the original text, picks a chunk, say15 words, and pastes that on my doc.1.
- When I’ve translated that chunk (by overtyping the original) I execute the macro again and it goes, picks the next 15 words and adds them to my doc.1, and so on.
- Besides, on the original Doc.2, it turns a different color the part of the text already done, so if I need to check something it is easy for my eyes to fall near the spot I’ve reached. Here’s the code:


Code:
 
    Windows("Doc.2").Activate
    Selection.MoveRight Unit:=wdWord, Count:=15, Extend:=wdExtend
    Selection.Copy
    Selection.Font.Color = wdColorBlue
    Selection.MoveRight Unit:=wdCharacter, Count:=1
 
    Windows("Doc.1").Activate
    Selection.PasteAndFormat (wdPasteDefault)
    Selection.MoveLeft Unit:=wdWord, Count:=15
    Overtype = Overtype
What I would like is for that macro (or any other I may think of in the future) to be called automatically by juust entering a given single character in my doc.1.
Thank you again for your interest.
ACA
Reply With Quote
  #7  
Old 06-17-2011, 03:26 AM
macropod's Avatar
macropod macropod is offline Calling for an action when typing a character Windows 7 32bit Calling for an action when typing a character Office 2007
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Hi ACA,

You could possibly use a macro like the following. It goes though all sentences in the document, asking for you to translate them. If you edit or leave a given sentence alone, the next sentence is selected. Pressing cancel exits the macro.
Code:
Sub Translation_Assistant()
Dim Rng As Range, Rslt
With ActiveDocument
  For Each Rng In .Sentences
    With Rng
      .MoveEndWhile Cset:=" ", Count:=wdBackward
      .End = .End - 1
      .Select
      If .Style <> "Trans" Then
        Rslt = InputBox("Please translate this sentence.", "Sentence translation", .Text)
        If Rslt = vbNullString Then Exit Sub
        .Text = Rslt
        .Style = "Trans"
      End If
    End With
  Next
End With
End Sub
The code assumes the existence of a Character Style (which you can easily create) named 'Trans'. This doesn't need any special attribute, though you could give it a font colour, for example. This Style is applied to each sentence as it's translated/skipped. Any sentences already having that Style will be skipped next time you run the macro.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 06-17-2011, 10:28 AM
ACA ACA is offline Calling for an action when typing a character Windows 7 Calling for an action when typing a character Office 2007
Advanced Beginner
Calling for an action when typing a character
 
Join Date: Aug 2010
Posts: 31
ACA is on a distinguished road
Default

Paul, I tank you very warmly for your effort and your insistence in following my query to this point.
Your approach is very new to me, but clever and knowledgeable, and works all right.

Thanks again. Bless you.
Aca
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to link an action on one slide on a powerpoint with the same action on another slevinmj PowerPoint 0 02-24-2011 05:38 AM
Re-Calling Sent Email freschij Outlook 1 12-06-2010 09:16 PM
Change Action Setting Path gskelton PowerPoint 0 02-27-2010 03:20 PM
calling images with a button sammer021486 PowerPoint 0 01-13-2010 08:24 AM
Highlighted Selection on Action Settings mos7sad PowerPoint 0 10-12-2009 07:48 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft