Consulting

Results 1 to 3 of 3

Thread: Copy from Excel to Word

  1. #1

    Copy from Excel to Word

    Hi everyone,

    Now I am trying to copy a range of cells from Excel to Word, now this is all not very hard to do and I have accomplished that with a little help from the good old kb, but the problem is that i do not want it to appear in a table form as it does normally. Now I can accomplish that by pasting it as a figure but then my hyperlinks in Excel stop working.
    Now I have no experience whatsoever on macro's in Word and I prefer the macro to be based within excel. Here is what I have thus far.


    Sub PasteToWord()
    Dim AppWord         As Word.Application
        Dim i As Long
    Set AppWord = CreateObject("Word.Application")
        AppWord.Visible = True
         '  Change the range to suit your needs. See the How to Use for this code
        With Worksheets("hoofd")
        i = 6
        Do
        i = i + 1
        Loop Until .Range("A" & i) = ""
        .Range("A6:A" & i).SpecialCells(xlCellTypeVisible).Copy
        AppWord.Documents.Add
        AppWord.Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
            Placement:=wdFloatOverText, DisplayAsIcon:=False
        End With
    Application.CutCopyMode = False
    Set AppWord = Nothing
    End Sub

  2. #2
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    How do you want it to appear?

    Can't you just turn gridlines off?

  3. #3
    VBAX Mentor XL-Dennis's Avatar
    Joined
    May 2004
    Location
    ?stersund, Sweden
    Posts
    499
    Location
    Hi,

    Below You find an example on how to achieve it by using bookmark to add a hyperlink to the picture:

    Option Explicit
    Sub PasteToWord()
    Dim AppWord As Word.Application
    Dim i As Long
    Dim wsSheet As Worksheet
    Dim rnData As Range
    Set wsSheet = ThisWorkbook.Worksheets("hoofd")
    With wsSheet
        Set rnData = .Range(.Range("A6"), _
                      .Range("A65536").End(xlUp).SpecialCells(xlCellTypeVisible))
    End With
    rnData.Copy
    Set AppWord = CreateObject("Word.Application")
    With AppWord
        .Documents.Add
        .Selection.PasteSpecial Link:=False, DataType:=wdPasteMetafilePicture, _
                       Placement:=wdFloatOverText, DisplayAsIcon:=False
        With .ActiveDocument
            .Shapes("Picture 2").Select
            .Bookmarks.Add ("Test")
            .Hyperlinks.Add .Bookmarks("Test").Range, "c:\test.txt"
        End With
    End With
    Application.CutCopyMode = False
    AppWord.Visible = True
    Set AppWord = Nothing
    End Sub
    Kind regards,
    Dennis
    Kind regards,
    Dennis

    ExcelKB | .NET & Excel | 2nd edition PED


Posting Permissions

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