473,324 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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 8122
NeoPa
32,556 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,556 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,556 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,556 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

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

Similar topics

7
by: Bani | last post by:
Is it possible to get browser-menu events (IE) into Javascript? I have a special copy/paste on the onkeydown event (ctrl+c/ctrl+v). Now the users would like to trigger it also from the browser...
1
by: Sean Howard | last post by:
Dear All, As is my want I need to do something in Access that seems simple but cannot fathom out. I have main form with two subforms, both datasheets with an almost identical table structure....
4
by: Legendary Pansy | last post by:
I was checking out the 101 C# Samples, specifically Windows Forms - Use the Clipboard. I took a look at the code for a while, and I understand what the program is doing with the cut, copy, pasting...
3
by: Rachel Suddeth | last post by:
This may not be the right forum, but it's a problem I chiefly come across when trying to post here. When I do a copy/paste from VS, the text always looks really weird (and even if I'm in an...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
0
by: Richard Crowley | last post by:
I have a dynamically-generated asp web page which uses Office Web Components to display an Excel bar chart of the user-selected data. The page works fine, but the users would like to copy-n-paste...
1
by: obeast215 | last post by:
Good Afternoon, I am trying to create a macro that will copy and paste from the 3270 IBM Reflection program to either Microsoft Access database or Microsoft Excel. I already understand the...
5
by: deve8ore | last post by:
Hello, I have a Word document called (), a named range that will open up a new Word doc dependent on what a user selects in Excel. Could someone please guide me on how to set up VBA code to...
8
by: jh | last post by:
I'd like to copy/paste into a listbox during runtime. I can do this for a textbox but can't figure out how to accomplish this for a listbox. Any help? Thanks.
3
by: questionit | last post by:
Some websites disable the Windows copy and paste feature to use on thier website. A text can not be copied and pasted either from using shortcuts : CTRL+C, CTRL+V or from using copy, paste option...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.