469,578 Members | 1,742 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,578 developers. It's quick & easy.

Copy and paste into word from access

Hi all,


It's a little late in the day for me so please forgive as i need my bed.!!


The issue is i need to open a word doc (say "c:\temp.doc) and paste into it, but i only can work out how to open a NEW doc
Expand|Select|Wrap|Line Numbers
  1.             ' Creates a new document and pastes Clipboard contents.
  2.           ' Saves the document in the Word directory and closes the
  3.           ' document.
  4.  
  5.  Set NewObject = CreateObject("Word.Basic")
  6.           NewObject.filenew
  7.           NewObject.editpaste
  8.           NewObject.filesaveas DocPath & "\" & NewDoc
  9.           NewObject.FileClose
Sep 29 '09 #1

✓ answered by NeoPa

@NeoPa
In Excel and Word it is often very easy to determine what code is required to to perform a particular function.

Simply select Tools \ Macro \ Record New Macro and execute the function manually. When complete, just look at the code it produces. It's pretty obvious what each command does and you can use the Help system to refine it, change options & parameters etc.

6 7554
NeoPa
32,198 Expert Mod 16PB
I'm assuming you're executing this code within an Access module of some kind yes?

Check out Application Automation. There may be some references in there to help.
Sep 29 '09 #2
Yes i am.

Now i can open the doc but cant figure out how to paste this time round.
Expand|Select|Wrap|Line Numbers
  1. Set NewObject = CreateObject("Word.Application")
  2. NewObject.Visible = True
  3. NewObject.Activate
  4. NewObject.ChangeFileOpenDirectory "D:\"
  5. NewObject.Documents.Open FileName:="Point.dotx"
  6.  
  7.  
  8. 'now not working !!!!!!!!!
  9.          NewObject.Document.editpaste
  10.          NewObject.filesaveas DocPath & "\" & NewDoc
  11.          NewObject.FileClose
  12.  
  13.           ' Frees the memory used by the objects.
  14.           Set NewObject = Nothing
Sep 29 '09 #3
NeoPa
32,198 Expert Mod 16PB
I think you're looking for :
Expand|Select|Wrap|Line Numbers
  1. Call NewObject.Selection.Paste
where NewObject is an object of type Word.Application.
Sep 29 '09 #4
NeoPa
32,198 Expert Mod 16PB
@NeoPa
In Excel and Word it is often very easy to determine what code is required to to perform a particular function.

Simply select Tools \ Macro \ Record New Macro and execute the function manually. When complete, just look at the code it produces. It's pretty obvious what each command does and you can use the Help system to refine it, change options & parameters etc.
Sep 29 '09 #5
How to Extract a embeded OLE word document and paste & save it into an exteranl location

Sorry some sloppy coding!
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command31_Click()
  2.  
  3.           Dim NewObject As Object
  4.           Dim NewDoc As String
  5.           Dim DocPath As String
  6.  
  7.           ' Name of the new document to create.
  8.           Dim Dnam As String
  9.           Dnam = Me.Text32 & ".doc"
  10.           NewDoc = Dnam
  11.  
  12.           ' Where to store the new document.
  13.           ' DefaultDir$(9) returns the Word directory path.
  14.           ' See DefaultDir$() in Word's on-line help for more options.
  15.           ' Note: The "$" is not used when calling DefaultDir via
  16.           ' OLE Automation.
  17.           DocPath = "D:\Kpic"
  18.  
  19.           ' Copies the embedded object to Clipboard.
  20.           Me!Photograph.Verb = 0
  21.           Me!Photograph.Action = 7
  22.           Me!Photograph.Object.Application.WordBasic.EditSelectAll
  23.           Me!Photograph.Object.Application.WordBasic.EditCopy
  24.           Me!Photograph.Action = 9
  25.           DoEvents
  26.  
  27.  
  28.           ' Opens a word template document and pastes Clipboard contents.
  29.           ' Saves to a new file and document in the Word directory and closes the
  30.           ' document.
  31.  
  32. Set NewObject = CreateObject("Word.Application")
  33. NewObject.Visible = True
  34. NewObject.Activate
  35. NewObject.ChangeFileOpenDirectory "D:\"
  36. NewObject.Documents.Open FileName:="Point.dotx"
  37. NewObject.Selection.Paste
  38.          'removes an extra space!
  39.         NewObject.Selection.TypeBackspace
  40.  
  41.          NewObject.ActiveDocument.SaveAs FileName:=DocPath & "\" & NewDoc
  42.  
  43.          NewObject.ActiveDocument.Close
  44.  
  45.           ' Frees the memory used by the objects.
  46.           Set NewObject = Nothing
  47.  
  48.           MsgBox DocPath & "\" & NewDoc & " was created successfully."
  49.       End Sub
Sep 29 '09 #6
NeoPa
32,198 Expert Mod 16PB
Paul, it's not clear what your intention is posting this code. I'm guessing it's a notification that you now have it working and are politely posting your solution for us to clarify the thread. If so, thank you. We appreciate that attitude. If not, please clarify.

PS. Please remember to use the CODE tags when posting code in future. I have amended each of your posts so far for you and left an edit comment. Using the CODE tags is mandatory on the site.
Sep 29 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Sean Howard | last post: by
4 posts views Thread by Legendary Pansy | last post: by
3 posts views Thread by Rachel Suddeth | last post: by
7 posts views Thread by lgbjr | last post: by
1 post views Thread by obeast215 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.