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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Someone must know how to do this....... 2

Status
Not open for further replies.

itsfisko

Technical User
Jan 19, 2002
226
GB
Hi perhaps you could help with my problem?
I have X number of word documents submited by pupils Into an inbox on a shared area on the server. I open these one by one assess them, mark them and post them back into an Out box. I have prepared a standard mark set on another word doc and at the moment I cut and paste the mark to their work before moving it to the out box, however I would like to have a submit button to allow me to put the txt from one document to the other. I imagine a minimised word doc containing my marks to be set "always on top" and to call up the pupils work, mark it and click a button to add the mark before I close their work and place it in the out box. Any ideas you clever lot ? Some lead, some follow....I just Hope!
 
I believe this is the second time you're trying this one. Since you got no response on your first attempt, maybe you need to provide some more information. What is a "standard mark set"? What is your existing code, and what does it do, what does it need to do?
Rob
[flowerface]
 
Hi Rob
Yep you are right its the Nth time i've tried to get somewhere with this.
OK the senario is:- I have an excel (could be word doesn't matter) File and on this file I have a set of statements which I wish to apply to the work being marked.
I open the work to be marked,decide on the mark and click on a button on my statement file next to the grade /mark I want to award, This is then placed on the work to be marked (a word document) before I save it (this will probably be part of the macro /script) I hope this explanation helps and that Some one can solve or put me on the right track.
Ta John.
Some lead, some follow....I just Hope!
 
PS
I meant to include this,

Sub Button1_Click()

' Button1_Click Macro
' Macro recorded 11/02/2003 by itsfisko



Range("A1").Select
selection.Copy
Application.ActivateMicrosoftApp xlMicrosoftWord

Range("A1").PasteSpecial (THIS IS WHERE IT FAILS)

End Sub Some lead, some follow....I just Hope!
 
To TAKE CONTROL of another MS App from within Excel, don't use ActivateMicrosoftApp. Instead, use something like:

dim wd as word.application
set wd=getobject(,"word.application")
range("A1").copy
wd.selection.paste

If your mark is just plain text, you're probably better off using:

wd.selection.typetext range("A1").text

Play around with this - you'll need to fine-tune it (and get to understand some of Word VBA's idiosyncracies) to get it just the way you want it, but this should be a start.
Rob
[flowerface]
 
Cheers rob I'll give it a go and let you know
John Some lead, some follow....I just Hope!
 
Hi Rob
I have had a play and it still gets stuck, am I doing something thick?
I asume that I should be putting your idea into Excel?
I get an error User-defined type not defined (the wd as word.application) is highlighted any ideas, I will continue to play around and see if I can fix it. Some lead, some follow....I just Hope!
 
itsfisko - sorry to butt in, but the error you're getting is because you haven't set a reference to Word in your Excel project. In the VBA editor, goto TOOLS > REFERENCES and search for Microsoft Word x.0 object Library where x = 8 for Office 97, 9 for Office 2k and 10 for office XP.


HTH

Cheers
Nikki
 
Thanks Nikki. this may it !! Some lead, some follow....I just Hope!
 
tried the reference, no go. I will beat this it seems so stupidly simple. Some lead, some follow....I just Hope!
 
Try using simply

dim wd
instead of
dim wd as word.application

This will not allow you to have VBE automatically suggest properties and methods, but it should get rid of the error you're getting. But the reference Nikki suggested should work - could you post the exact code you're working with now?
Rob
[flowerface]
 
Sub Button1_Click()
'
' Button1_Click Macro
'
Rob / Nikki

This sort of works but deletes work on word doc but getting there will try your suggestion


Range("A1").Select
Selection.Copy
Application.ActivateMicrosoftApp xlMicrosoftWord


ActiveDocument.Range.PasteSpecial

Thanks again John

End Sub Some lead, some follow....I just Hope!
 
instead of activedocument.range.pastespecial, use
selection.pastespecial,
after putting the selection at the position where you need the text.
Rob
[flowerface]
 
Rob
Thats my problem How to tell the VB where to put the copied text. I am very new to all this but it will not beat me. Thanks again John Some lead, some follow....I just Hope!
 
It was my impression that you had been working in Word manually, and positioned the selection marker at the appropriate location. Otherwise, you'll need to do some kind of Find to get to the right location. Or, if it's simply at the end of the document, try
wd.Selection.EndKey Unit:=6 'wdStory=6

In general, the word macro record feature is fairly useful to figure out how to code something in VBA. Unlike Excel, during Word macro recording you can't use the mouse to move your selection around, so you'll need to use keystrokes.
Rob
[flowerface]
 
Hi again Rob
No I'm in excell and coping by VB to a word document that already contains some work.
The trouble with my script is that it deleats what I have on the word doc, Still trying......

John 11.40pm England Some lead, some follow....I just Hope!
 
Well, yes, the previous code you posted will indeed delete what's already there. But the selection.pastespecial I suggested shouldn't. If you provide more information about exactly what you are trying to do (where to position the mark, etc), I'm sure we can help. The more specific, the better.
Rob
[flowerface]
 
Hi all,
I think I have it licked. The code below will paste the contents of a cell in EXCEl(this will contain a GRADE mark & comment on the marked work) to below the last paragraph in an OPEN WORD document,save it and then close. My final stage is to sort out the code to get the WORD document properties for the AUTHOR (this being the pupils USERNAME)and using this to place in the save as string to save the document directly back to the home directory of the person who wrote it.
THE CODE (for excel(on button click))

Sub Button1_Click()

' Button1_Click Macro Created by J.Fisk
Range("A1").Select
Selection.Copy
Application.ActivateMicrosoftApp xlMicrosoftWord
Set Range0 = ActiveDocument.Content
Range0.Collapse Direction:=wdCollapseEnd
Range0.Paste

If ActiveDocument.Saved = False Then ActiveDocument.Save
ActiveDocument.Close

End Sub


Thanks all for your help :)I Some lead, some follow....I just Hope!
 
Hi all Please note that it should have been

Range0.Pastespecial
Now to find a way to get the author from the word doc and use it in my save string....... Some lead, some follow....I just Hope!
 
Hiya ...

This gets the author's name in Win2000:
Code:
ThisDocument.BuiltInDocumentProperties("Last Author")

Dunno if it's usable for 97 but it is available in Word XP as well


Hope this helps

Cheers
Nikki
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top