Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pasting with script from word

Status
Not open for further replies.

VLG711

Technical User
May 30, 2001
95
US
Hi Guys,
I'm having trouble getting information from a word document. I want to copy line by line from the word document and paste each into different windows in ProComm. I've created a macro in word that copies a line and moves the cursor to the next line. I'm attempting to connect to word, call the macro, and paste the info into ProComm and give a RETURN. I can get it to all work but when I run the script again it continues to paste the same line. I found if I Alt+Tab to the Word window then back to ProComm and run the script again it will paste the next line, but what a pain. Any suggestions regarding how I can fix this?
And please remember I’m no programmer.


proc main
long LinkVar, SystemVar


if ddeinit SystemVar "msWORD" "System"

if ddeinit LinkVar "msWORD" "TESTDDEscripts.doc"

ddeexecute LinkVar "Copy_Next_Line[Copy_Next_Line()]"

ddeunadvise LinkVar "TESTDDEscripts.doc"
ddeterminate LinkVar
ddeterminate SystemVar
pastetext
transmit "^M"
else
errormsg "Couldn't establish DDE link to Document!"
endif
else
errormsg "Couldn't establish DDE link to Word!"
endif
endproc


Thanks in advance.
VLG711
 
Without your macro I can't offer in-depth advice, but here are a couple suggestions. First, when you run the script without doing the Alt-Tab, is it always selecting the first line in the Word document, or does it get the line that the cursor is on? What I am wondering is if the ddeinit is causing the first line to always be selected.

One thing you might want to try is using a for loop and see if you can get multiple lines copied in one script run. Here is a modified script to test the theory:

proc main
long LinkVar, SystemVar
integer iLoop

if ddeinit SystemVar "msWORD" "System"
if ddeinit LinkVar "msWORD" "TESTDDEscripts.doc"
for iLoop = 1 upto 5
ddeexecute LinkVar "Copy_Next_Line[Copy_Next_Line()]"
pastetext
transmit "^M"
endfor
ddeunadvise LinkVar "TESTDDEscripts.doc"
ddeterminate LinkVar
ddeterminate SystemVar
else
errormsg "Couldn't establish DDE link to Document!"
endif
else
errormsg "Couldn't establish DDE link to Word!"
endif
endproc

aspect@aspectscripting.com
 
Here's my Macro.
Sub Copy_Next_Line()
'
' Copy_Next_Line Macro

Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
End Sub
 
I would recommend posting your macro to one of the Office forums on Tek-Tips (I think there are two if I recall correctly). My guess is that Word needs to be the active application for the copy or move to succeed. Someone more experienced with Word macros in those forums will hopefully be able to point you in the right direction.


aspect@aspectscripting.com
 
The following worked with some minor flaws. The Word document has to be minimized and the cursor must be at the start of line 1. If you know a way to place the cursor at the beginning please let me know.


proc main

long LinkVar,SystemVar
integer iLoop

if ddeinit SystemVar "msWORD" "System"


if ddeinit LinkVar "msWORD" "C:\TESTDDEscripts.doc"

for iLoop = 1 upto 3
winfocus "TESTDDEscripts.doc - Microsoft Word"
ddeexecute LinkVar "Copy_Next_Line[Copy_Next_Line()]"
pastetext
transmit "^M"
waitfor ">>" forever
endfor
ddeunadvise LinkVar "C:\TESTDDEscripts.doc"
ddeterminate LinkVar
ddeterminate SystemVar

else
errormsg "Couldn't establish DDE link to Document!"
endif
else
errormsg "Couldn't establish DDE link to Word!"
endif

endproc


Macro:

Sub Copy_Next_Line()


Selection.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1


End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top