Results 1 to 6 of 6

Thread: Copy paste issue. [Excel to word]

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    5

    Question Copy paste issue. [Excel to word]

    Hey guys.
    I've made a script where you can load/import an excel file and paste this in word.
    Here is the code:
    Code:
    Private Sub CommandButton2_Click()
        Dim lngCount As Long
        i = 1
        With Application.FileDialog(msoFileDialogOpen)
            .AllowMultiSelect = False
            .Show
            For lngCount = 1 To .SelectedItems.Count
             OpenExcelWorkbook .SelectedItems.Item(lngCount)
            Next lngCount
        End With
    End Sub
    Public Sub OpenExcelWorkbook(file As String)
        Dim app As Object
        Dim workbook As Object
        Set app = CreateObject("Excel.Application")
        Set workbook = app.Workbooks.Open(file)
        app.Sheets("Blad1").Range("A:J").Copy
    End Sub
    Private Sub plakexcel()
        Selection.GoTo What:=wdGoToPage, Count:=8
        Selection.MoveDown Unit:=wdLine, Count:=10
        Selection.PasteAndFormat (wdPasteDefault)
        Selection.MoveUp Unit:=wdLine, Count:=1
    sluiten
    End Sub
    Now here comes my issue. Once I copy+paste rows A to J, all works well. But once field row A overlaps row B because of the width of the text, it puts it on the next line.

    Or when row A to J are filled with text it pushes it off to the edge of the document.

    Do you guys have any better methods to 'import' excel rows A to J in word?

    Thanks in advance.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Copy paste issue. [Excel to word]

    as alternates
    you can insert a workbook object into your document
    or you can insert the data into a table
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    5

    Re: Copy paste issue. [Excel to word]

    Any example on how to do this?
    The issue is it will paste everything, so when row J is out of range of the A4 sheet its not visible or puts it on the next row ;(
    I'll figure that out, but how do i insert it into a table or workbook object?
    The workbook object won't auto resize to the desired length... Will it?

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Copy paste issue. [Excel to word]

    The workbook object won't auto resize to the desired length... Will it?
    no idea

    i would look at your problem except that i can not open later version off files in office 2000
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    5

    Re: Copy paste issue. [Excel to word]

    I think the workbook part is a no-go. When I insert a workbook it gets very small and I could resize it but I can't get it to auto-resize I think.

    P.S. Want me to PM you Office 2010? Can be installed next to 2000. (you can keep both versions)

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Copy paste issue. [Excel to word]

    P.S. Want me to PM you Office 2010? Can be installed next to 2000. (you can keep both versions)
    thanks, but no, with the speed of the internet here it would take a week

    you can try saveas the files as earlier version
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Posting Permissions

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



Click Here to Expand Forum to Full Width