Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-15-2016, 09:03 AM
dan88 dan88 is offline Paste Table From XL - Word Error -  Bad Parameter Windows 10 Paste Table From XL - Word Error -  Bad Parameter Office 2016
Novice
Paste Table From XL - Word Error -  Bad Parameter
 
Join Date: Feb 2016
Posts: 24
dan88 is on a distinguished road
Default Paste Table From XL - Word Error - Bad Parameter

Hi folks,



I am copying tables from excel using Paul's code below.

I modified it to use excel ranges that feed into each array.

The only issue I have now is it pastes the first table from excel into the first bookmark.

Then i get error - bad parameter on line

.MoveEnd wdTable, 1

https://www.msofficeforums.com/word-...cel-table.html

http://www.vbaexpress.com/forum/show...Tables-To-Word

Code:
Sub XLTablesWord()


Dim i           As Long

Dim TableArray() As Variant
TableArray = Range("TableNames")

Dim BookmarkArray() As Variant
BookmarkArray = Range("BookmarkNames")


    
    '---------PASTE TO DOCUMENT
    With GetObject("C:\Users\Dan\Desktop\Tables.docx")
    
    
        .Parent.Visible = True
        
        For i = LBound(TableArray) To UBound(TableArray)
            For Each sh In Sheets
                
            For Each lob In sh.ListObjects
                
                
            If TableArray(i, 1) = lob.Name Then
                
            lob.Range.Copy       'Copy Table Range from Excel
                
                
            With .Bookmarks(BookmarkArray(i, 1)).Range    'Paste Table into MS Word & format
            
                .PasteExcelTable LinkedToExcel:=False, WordFormatting:=False, RTF:=False
                
                .MoveEnd wdTable, 1
                .Tables(1).AutoFitBehavior (wdAutoFitWindow)
                
                End With
                End If
                Next lob
            Next sh
        Next i
    End With
   
End Sub
This has me stumped, I am not sure what the problem is

Many thanks for any advice


dan
Reply With Quote
  #2  
Old 06-15-2016, 08:12 PM
macropod's Avatar
macropod macropod is offline Paste Table From XL - Word Error -  Bad Parameter Windows 7 64bit Paste Table From XL - Word Error -  Bad Parameter Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,363
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The only error I can see as likely to be generated on that line is 'variable not defined' - and then only if you haven't set a reference to the Word object library.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 06-16-2016, 05:36 AM
dan88 dan88 is offline Paste Table From XL - Word Error -  Bad Parameter Windows 10 Paste Table From XL - Word Error -  Bad Parameter Office 2016
Novice
Paste Table From XL - Word Error -  Bad Parameter
 
Join Date: Feb 2016
Posts: 24
dan88 is on a distinguished road
Default

Hi Paul,

that seemed to do the trick set the reference to the Word Library

but sadly another error has appeared.

For some reason it is skipping the middle table
example

Arrays Set Up like this

Table1 ------BM1
Table2 ------BM2
Table3 ------BM3


Table3 - gets pasted into BM2

and nothing in BM3
any ideas?

thank you
dan
Reply With Quote
  #4  
Old 06-16-2016, 05:39 AM
macropod's Avatar
macropod macropod is offline Paste Table From XL - Word Error -  Bad Parameter Windows 7 64bit Paste Table From XL - Word Error -  Bad Parameter Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,363
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Without actually seeing the problem Word document and Excel workbook, it can be difficult for anyone to diagnose the issue. Can you attach a document & workbook to a post with some representative content (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Paste Table From XL - Word Error -  Bad Parameter How can I paste text that's not formatted as a table into a new table? WaltR Word 2 10-11-2014 03:16 PM
Paste Table From XL - Word Error -  Bad Parameter How to paste the data from one table into the cells of another table, without overwriting anything CClio333 Word Tables 1 08-12-2014 05:17 PM
Paste Table From XL - Word Error -  Bad Parameter Is it possible to copy non-contiguous rows of a Table and paste them as a separate Table in Word? Joey Cheung Word Tables 1 08-12-2014 05:15 PM
Paste Table From XL - Word Error -  Bad Parameter Can pass .expression as a parameter? tinfanide PowerPoint 4 12-28-2012 06:14 PM
Word 2003 Table of Contents Error Message ktcolburn Word 1 10-30-2005 06:14 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:12 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft