Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228

    Type mismatch when trying to paste range

    Note: This isnt code within access, Im using data from access in an excel table which I would like to then paste into a word document.



    This is the code I currently am using:
    Code:
    Sub ExcelRangeToWord()
    
    
    Dim objWord As Object
    Dim ws As Worksheet
    
        Set ws = ThisWorkbook.Sheets("RISKS")
        Set objWord = CreateObject("Word.Application")
    
        objWord.Visible = True
    
    
    'Optimize Codee
      Application.ScreenUpdating = False
      Application.EnableEvents = False
    
    
      'open the word doc
          objWord.Documents.Open "C:\Users\ah\Desktop\RAM-HS-007  BAU RAMS.docx" 'change as required
    
    
    'pastes the value of cell I19 at the "heatlosses" bookmark
        With objWord.ActiveDocument
            .Bookmarks("RISKS").Range.Text = ws.Range("A1:I18").Value
        End With
    
    'Optimize Code
    Set objWord = Nothing
      Application.ScreenUpdating = True
      Application.EnableEvents = True
    
    'Clear The Clipboard
      Application.CutCopyMode = False
    
    End Sub
    This code will work fine if "ws.Range("A1:I18").Value" is changed to "ws.Range("A1").Value" but abviously it only displayes the contents of cell A1 in the word document.

    Thats the first problem, pasting in the table. The second problem would be definind the range. The range may not need to be up to row 18. The document is for showing risks on a site (pulled from the DB into excel). If there is only 1 risk then we dont need to copy in 18 rows. (I hope this makes sense)

    Any help appreciated, even if its not the answer.

    Thanks a lot, Andy.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Copy the range to the clipboard,
    then paste clipboard to word.

  3. #3
    Join Date
    Jun 2015
    Location
    Wales. Land of the sheep.
    Posts
    1,228
    Thanks a lot. I have that working now.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Type Mismatch
    By Alex Motilal in forum Programming
    Replies: 5
    Last Post: 02-04-2017, 05:57 PM
  2. Type 13 (Type Mismatch) error
    By sdel_nevo in forum Programming
    Replies: 5
    Last Post: 01-22-2016, 10:01 AM
  3. Type mismatch
    By mmaule in forum Access
    Replies: 4
    Last Post: 02-23-2015, 11:47 AM
  4. type mismatch
    By Compufreak in forum Access
    Replies: 5
    Last Post: 08-08-2012, 11:00 AM
  5. Type Mismatch - HELP!
    By jgelpi in forum Programming
    Replies: 3
    Last Post: 07-17-2009, 03:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums