Question

Need VBA code to swap two words written on left and right of the current cursor position in a wor...

need VBA code to swap two words written on left and right of the current cursor position in a word document file.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

VBA code to swap two words written on left and right of the cursor position in a word document file. Here is the macro for it.

Sub swap()

Selection.MoveRight Unit :=wdWord, Count :=1; Extend:=wdExtend

Selection.Cut

Selection.MoveRight Unit :=wdWord, Count :=1

Selection.Paste

Selection.MoveLeft Unit :=wdWord, Count :=1; Extend:=wdExtend

Selection.Cut

Selection.MoveLeft  Unit :=wdWord, Count :=2

Selection.Paste

End Sub

Below are the keystrokes for the above macro:-

1. Ctrl+Shift+->

2.Ctrl+X (The first word is cut)

3. Ctrl+-> (The insertion pointer hops over the conjuction , and or or)

4. Ctrl+V (The word is pasted after the conjuction)

5. Ctrl + Shift + ->

6. Ctrl +X (The word after the conjuction (now after the first word you pasted in Step 4) is selected and cut)

7. Ctrl+<- , Ctrl +<- (The cursor moves back to just before the conjuction)

8. Ctrl +V (The second word is pasted)

Add a comment
Know the answer?
Add Answer to:
Need VBA code to swap two words written on left and right of the current cursor position in a wor...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need this problem to be solved in Excel VBA code. Need full code in VBA....

    I need this problem to be solved in Excel VBA code. Need full code in VBA. Please solve 1st Task : '5 or 0'. Please help me urgently with proper answer and coding solutions which I can run in Excel/vba. Thanks Course: Programming languages Second laboratory work File and string processing Create a program that processes text file according to task variant. Requirements: 1. Create text file (use notepad) with some lines of data according to task variant. 2. Ask...

  • What is the terminal voltage Vba of the "unknown" battery? (The current is to the right.)...

    What is the terminal voltage Vba of the "unknown" battery? (The current is to the right.) Express your answer to two significant figures and include the appropriate units. What is the terminal voltage Vba of the "unknown" battery? (The current is to the left.) Express your answer to two significant figures and include the appropriate units.

  • ASAP. I need VBA code, for Excel please 5. Create text file with notepad. Each line...

    ASAP. I need VBA code, for Excel please 5. Create text file with notepad. Each line contains only one word. Open it and, if the word begins with capital letter, output it to column A, otherwise in column B.

  • I have the current code that is working. I need to edit it so that I...

    I have the current code that is working. I need to edit it so that I am only counting strings that are after the word 'From' in a text file. Right now it's counting all words, but I just need the From email addresses in a text file. I think the issue if in the if/else loop but nothing I have tried works. Please help! 1 import string 2 fhand open('C: \Users \Brooke\Canopy scripts mbox-short.txt') 3 counts dict( 4 for...

  • Problem B: Clean up your potty mouth: blogging software Online blogs and other written content generation...

    Problem B: Clean up your potty mouth: blogging software Online blogs and other written content generation are very popular. However, as we try different ways to allow anybody on the internet to create and share written content, we run into a problem. A lot of people on the internet have foul potty-mouths and write lots of bad words. The common solution to this is to perform some form of automatic content filtering to either remove or obscure inappropriate text on...

  • I need this code to be written in C language. Also, I'm using Xcode on mac...

    I need this code to be written in C language. Also, I'm using Xcode on mac so I need the steps in order to know how to do it. Please save the program with the name 'files.c' Write a program that merges two files as follows. The two files are in the docsharing which you can download it. One file will contain usernames (usernames.txt): foster001 smith023 nyuyen002 The other file will contain passwords (passwords.txt): x34rdf3e P43e4rdd w32eds22 The program should...

  • I need help figuring out how to code this in C++ in Visual Studio. Problem Statement:...

    I need help figuring out how to code this in C++ in Visual Studio. Problem Statement: Open the rule document for the game LCR Rules Dice Game. Develop the code, use commenting to describe your code and practice debugging if you run into errors. Submit source code. Use the document to write rules for the user on how to play the game in a text file. Then, using the information from the resource articles, create a program that will read...

  • I need help writing this C code. Here is the description: Let's say we have a...

    I need help writing this C code. Here is the description: Let's say we have a program called smart typing which does two things: The first letter of a word is always input manually by a keystroke. When a sequence of n letters has been typed: c1c2...cn and the set of words in the dictionary that start with that sequence also have c1c2...cnc then the smart typing displays c automatically. we would like to know,  for each word in the dictionary,...

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • I need to update this code: #include <iostream> #include <string> #include <cctype> using namespace std; int...

    I need to update this code: #include <iostream> #include <string> #include <cctype> using namespace std; int main() { string s; cout<< "Enter a string" <<endl; getline (cin,s); cout<< s <<endl; int vowels=0,consonants=0,digits=0,specialChar=0; for (int i=0; i<s.length(); i++) { char ch=s[i]; if (isalpha(s[i])!= 0){ s[i]= toupper(s[i]);    if (ch == 'a'|| ch == 'e'|| ch == 'i'|| ch == 'o' || ch == 'u') vowels++; else consonants++; } else if (isdigit(s[i])!= 0) digits++; else specialChar++; } cout<<"Vowels="<<vowels<<endl; cout<<"Consonants="<<consonants<<endl; cout<<"Digits="<<digits<<endl; cout<<"Special Characters="<<specialChar<<endl;...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT