problems with OLES

  • Thread starter Thread starter essorem
  • Start date Start date
E

essorem

Guest
hello! I have a form with an OLE object embedded(or linked) on it. The object is a word document. What I need to do is paste the text from that document into a new document. When I DoCmd.RunCommand acCopy it copies and pastes the whole object. Does anyone know how to access/select/paste/whatever the text from the word document?
 
I have done something similar by putting a macro in the word document that selects and copies all of the data. Then with VB in Access, I run the Word macro.
To paste, I use SendKeys "^v"
 
Okay that seems like it should work, but how do you access the word document in VBA? I can activate the OLE, but then I need to know how to either 1. run your macro or 2. send the copy and paste commands right there. Writing DoCmd.RunCommand etc will refer to the access program, while appWord.selection.Copy, will refer to the document that I need to be pasting into.
 
The document I open isn't embedded. It is just a file on our network. I use this code to open it and copy the text:

Set hotapp = CreateObject("Word.application")
Set hotdoc = hotapp.Documents.Open("Put the path to the document here")

hotapp.Visible = False
hotapp.Selection.WholeStory
hotapp.Selection.Copy
hotapp.ActiveDocument.Close


hotapp.Quit
Set hotapp = Nothing
Set hotdoc = Nothing

Then I open an Outloook e-mail form using similar code and add the SendKeys line to paste the text into the body of the e-mail. I can post the code for that, too, if you like. If you are just pasting into another Word document, I would think you could add a line to the code above setting hotdoc to the new file and then insert the SendKeys command.
I have seen warnings about using SendKeys. If the sequence is wrong it can cause problems. But the only other way I have heard of for pasting in VBA require you to deal with Windows API, which is over my head.
 

Users who are viewing this thread

Back
Top Bottom