+ Reply to Thread
Results 1 to 4 of 4

vba to copy from Excel to Word Doc

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    vba to copy from Excel to Word Doc

    Can somebody please help me move forward with my coding? The code I have constructed so far is attached, may be very crude and incomplete but it works to a point.

    What I am trying to do is; From command button on the active Excel Worksheet, open a specific Word doc, copy and paste a specific range from the Active Worksheet to a Bookmarked position in the Word doc, then run SaveAs. Would then do some manual editing to the Word Doc before closing it and returning to Excel.

    Sub cmd_Copy_to_Template()      'Opens a specific Word Doc from
                                    'a CommandButton on Excel sheet then copies and
                                    'pastes a given range from the Excel sheet to a
                                    'given location in the Template Word Document 
    
                     'step1: Declare your variables
                
    Dim MyRange As Excel.Range
    Dim wd As Word.Application
    Dim wdDoc As Word.Document
    Dim WdRange As Word.Range
                    'step2:Copy the defined range
     ThisWorkbook.ActiveSheet.Range("A17:C59").Copy
                    'Step 3: Open the target Word Document
     Set wd = New Word.Application
     Set wdDoc = wd.Documents.Open("C:\Users\Julian\Documents\My Documents\Jobsheet\Work carried out #New Template 2013(1).docx")
     wd.Visible = True
                     'Step4: Set  focus on the target bookmark
    Set WdRange = wdDoc.Bookmarks("JobSheet_Template_insert_point").Range
                    'Step5: Delete the old and paste the new
    On Error Resume Next
    WdRange.Tables(1).Delete
    WdRange.PasteAndFormat (wdPasteDefault)
                    'Step6: Reinsert the bookmark
    wdDoc.Bookmarks.Add "JobSheet_Template_insert_point", WdRange
                    'Step7: Memory clean up
    Set wd = Nothing
    Set wdDoc = Nothing
    Set WdRange = Nothing
    Set MyRange = Nothing
    
     End Sub

    What I am struggling with is:

    1) Bringing the Word Doc into view, (so is the active window)
    2) Prevent the Copy&Paste routine from being run again until the SaveAs operation has been completed and the Word Doc been closed ( so look to see if the Template Word Doc is already open and message to say it is and do you want to
    continue working on it, if yes - bring it back into view, if no – just close message leaving Word Doc open but reduced)
    3) Run SaveAs, but want to manually select/input the new file name. ( So need the SaveAs file dialogue box to be in view showing the other Word Docs in the folder, which is the same folder that the Word Doc Template is in)
    4) Ideally I would like skip/not copy blank rows, which where will almost certainly be somewhere in the middle of the range selected to copy.

    I hope that makes sense and someone out there can help me.

    Many thanks
    julhs

  2. #2
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: vba to copy from Excel to Word Doc

    Gentle nudge.

    I am actively working on this myself as well.

  3. #3
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: vba to copy from Excel to Word Doc

    Try nudge one last time

  4. #4
    Forum Contributor
    Join Date
    01-18-2012
    Location
    nr Salisbury, UK
    MS-Off Ver
    Excel 2010
    Posts
    126

    Re: vba to copy from Excel to Word Doc

    Having said one last nudge!!

    I so need some help with this.

+ 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. How to copy a Cell from Excel into Word, edit it as RTF and then save back in Excel
    By peterjgoodwin in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-10-2013, 06:42 PM
  2. Copy Many Word Docs to New Word Doc (Each Word Doc Should be on New Page)
    By realniceguy5000 in forum Word Programming / VBA / Macros
    Replies: 3
    Last Post: 05-05-2013, 03:28 AM
  3. VBA code that will follow excel hyperlink to word doc & copy text back into excel
    By crnadeau4 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-22-2013, 11:51 AM
  4. Copy from excel to word
    By JChandler22 in forum Excel General
    Replies: 1
    Last Post: 06-27-2007, 10:14 AM
  5. From excel - open word doc and copy form field contents to excel c
    By gnome88 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-25-2005, 08:05 PM

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