+ Reply to Thread
Results 1 to 8 of 8

Paste "CopyPicture" from Excel into a existing Word Document at the end of the document

  1. #1
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Paste "CopyPicture" from Excel into a existing Word Document at the end of the document

    Hi All,

    I have been trying to find a solution for a minor issue I am having.
    I have an Excel with the following VBA code (below), which Copy a table (as a picture) and paste it into a 'open' word document.
    I have this running. The issue is, it paste where the cursor is. This means, if the cursor is at the end of the document, it paste it where I want it.
    However, if the cursor in between the text, I still want it to paste it at the end of the document. However, I can't get this to work, for the cursor to jump to the end of the document before the paste.

    I have tried Endkey with move and so on, but I believe these VBA codes are for WORD VBA and not Excel VBA.

    Any help would be much appreciated.

    CWever

    Please Login or Register  to view this content.
    Last edited by CWever; 10-31-2020 at 01:51 PM. Reason: Solved.

  2. #2
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Paste "CopyPicture" from Excel into a existing Word Document at the end of the documen

    I'm no expert in this area, but I did have a project recently when I wanted to do something similar.

    What I did was create a bookmark in the MS-Word document at the point where the Excel data is to be pasted. I called the bookmark "t_schedule"

    Then in Excel with wdDoc as the open MS-Word doc:

    Please Login or Register  to view this content.
    There's probably a cleaner way if you always want to go to the end programmatically.

    If this doesn't work for you and there are no other responses you might want to ask a moderator to move this to the VBA section where you may be more likely to get help.
    Geoff

    Did I help significantly? If you wish, click on * Add Reputation to say thanks.
    If your problem has been resolved please select ?Solved? from the Thread Tools menu

  3. #3
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Re: Paste "CopyPicture" from Excel into a existing Word Document at the end of the documen

    GeoffW283,

    Yes I know of this "trick" with the Bookmark, however, the word documents is not always the same documents. And I'm not the one who is preparing the document. I'm creating a few excel templates which other will use to generate reports.
    I will take up your idea to move the post.

    MOD : would it be possible to move it to VBA thread? Thanks.

    CWever
    Last edited by AliGW; 10-31-2020 at 01:05 PM. Reason: PLEASE don't quote unnecessarily!

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,410

    Re: Paste "CopyPicture" from Excel into a existing Word Document at the end of the documen

    Thread moved.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Paste "CopyPicture" from Excel into a existing Word Document at the end of the documen

    Maybe :
    Please Login or Register  to view this content.
    1. I care dog
    2. I am a loop maniac
    3. Forum rules link : Click here
    3.33. Don't forget to mark the thread as solved, this is important

  6. #6
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Re: Paste "CopyPicture" from Excel into a existing Word Document at the end of the documen

    karedog,

    Thanks that works.

    Now I would like to understand why now the EndKey works, and what does the Const wdStory does.
    Much Appreciated.

    CWever

  7. #7
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Paste "CopyPicture" from Excel into a existing Word Document at the end of the documen

    You are welcome.

    Please read this webpage "Jumping to the Start or End of a Document" for Microsoft Word VBA :
    https://word.tips.net/T000120_Jumpin..._Document.html

    You can try to copy paste that code in your MsWord document to test that it really works.

    Now, since we controlling the word document from Excel (not by Word itself), we must call this code as the method of Word object, by :
    With wdAppExport '--> This is the Microsoft Word object
    .Selection.EndKey Unit:=wdStory '--> because this code is between [With wdAppExport .. End With) block, so we can call the Word VBA method from here



    And now about the wdStory,
    Because the MsWord object is referred by late binding --> GetObject(, "Word.Application"), Excel will not understand the value of MsWord's builtin constants, i.e. wdStory, so we must tell Excel, what the value of this constant is, by this line :
    Const wdStory As Long = 6

    Of course, you can also directly use the number, like this :
    .Selection.EndKey Unit:=6 '--> remove the "Const wdStory As Long = 6" code line, and replace the wdStory with "6", this will also worked
    but it is not meaningful to the programmer, what is this "6" refer to ? If we write wdStory, it is easier for us to remember, oh we want go to then end of the Story.

    That's it.

  8. #8
    Registered User
    Join Date
    07-10-2019
    Location
    Hengelo, NL
    MS-Off Ver
    Office 2016
    Posts
    35

    Re: Paste "CopyPicture" from Excel into a existing Word Document at the end of the documen

    Quote Originally Posted by karedog View Post
    You are welcome.
    Understood.

    I went so deep in to understanding Early Binding and Late binding, that I didn't think of this the reason why wdStory wouldn't be recognize. That went over my head.
    Thanks for explaining, now it is clear. And yes, I need Late Binding, because of different MS Office Versions and also different Win OS. This Template I'm creating is for 30 to 50 different people who will use it.

    thanks again,

    CWever

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How to open an existing Word document from Excel
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-18-2016, 06:04 AM
  2. VBA : Displays blank report after click "Generate Report" from excel to Word document
    By suchetherrah in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2016, 08:00 AM
  3. Replies: 0
    Last Post: 09-04-2014, 03:32 AM
  4. Add text to Existing Word Document if it Doesn't exist create Word Document
    By unstable81 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-10-2013, 12:15 AM
  5. Replies: 0
    Last Post: 10-13-2011, 05:51 AM
  6. Replies: 0
    Last Post: 10-12-2011, 08:25 AM
  7. Replies: 1
    Last Post: 10-17-2005, 04:05 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1