Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-19-2018, 05:57 AM
Homegrownandy Homegrownandy is offline Paste merge into word table Windows 10 Paste merge into word table Office 2016
Novice
Paste merge into word table
 
Join Date: Jul 2018
Posts: 15
Homegrownandy is on a distinguished road
Default Paste merge into word table

I'd like to know the VBA to paste merge.




also asked here in more detail: http://www.accessforums.net/showthread.php?t=72952


I'd just like to know if its possible before looking at workarounds.
Reply With Quote
  #2  
Old 07-20-2018, 12:02 AM
macropod's Avatar
macropod macropod is online now Paste merge into word table Windows 7 64bit Paste merge into word table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

For that you might use code like:
Code:
ActiveDocument.Tables(1).Range.Characters.Last.Next.PasteAppendTable
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 07-30-2018, 02:30 AM
Homegrownandy Homegrownandy is offline Paste merge into word table Windows 10 Paste merge into word table Office 2016
Novice
Paste merge into word table
 
Join Date: Jul 2018
Posts: 15
Homegrownandy is on a distinguished road
Default

Hi Paul, Sorry for the delay.

this is the closest thing I have seen to something that works.

Quote:
*resolved* I'm having a few issues, the table I append to does keep its formatting, but its moved to the right off the document. would you have a suggestion on how to handle that?
Also sometimes it pastes the table at the very top of the document not at the bookmark. I tried to add a 2 second delay but this problem still happens sometimes.

it seems about 50/50 if it actually pastes in the bookmark. But its not always predictable sometimes you get two good ones in a row sometimes two bad ones. I have similar code importing data from access which works without issue on the same document. Maybe its an issue with doing this with a table of data rather than one field.

If you have any ideas I would love to hear them,

Thanks a lot, Andy.
Reply With Quote
  #4  
Old 07-30-2018, 02:47 AM
macropod's Avatar
macropod macropod is online now Paste merge into word table Windows 7 64bit Paste merge into word table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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 code I posted has nothing to do with bookmarks - which your initial post here and at accessforums made no mention of. As coded, the macro simply pastes your added content to the end of the first table in the active document. Obviously, you'd need to change the table reference or edit the code so it refers to the bookmarked table.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 07-30-2018, 02:51 AM
Homegrownandy Homegrownandy is offline Paste merge into word table Windows 10 Paste merge into word table Office 2016
Novice
Paste merge into word table
 
Join Date: Jul 2018
Posts: 15
Homegrownandy is on a distinguished road
Default

I know it doesn't, I've added it to the code I was using.

Quote:
Application.Wait (Now + TimeValue("0:00:02"))
With objWord.ActiveDocument
.Bookmarks("RISKS").Range.Pasteappendtable

End With
which works about half the time. When it goes "wrong" it doesn't paste at the end of a table at all. It pastes on the first page at the top.

As I've been using bookmarks with no issue I didn't think it would be an issue. I thought I just needed to know the paste command which I couldn't find. (I was looking for merge not append)
Reply With Quote
  #6  
Old 07-30-2018, 02:53 AM
macropod's Avatar
macropod macropod is online now Paste merge into word table Windows 7 64bit Paste merge into word table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Try:
Code:
objWord.ActiveDocument.Bookmarks("RISKS").Tables(1).Range.Characters.Last.Next.PasteAppendTable
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-30-2018, 03:06 AM
Homegrownandy Homegrownandy is offline Paste merge into word table Windows 10 Paste merge into word table Office 2016
Novice
Paste merge into word table
 
Join Date: Jul 2018
Posts: 15
Homegrownandy is on a distinguished road
Default

Brilliant. I was getting
Quote:
Object doesn't support this property or method
But I removed the table name and it works perfect.

I don't know if I should be naming tables or even if its possible but its working perfect now.

Really appreciate your help, it will save hours of time.
Reply With Quote
  #8  
Old 07-30-2018, 03:24 AM
macropod's Avatar
macropod macropod is online now Paste merge into word table Windows 7 64bit Paste merge into word table Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
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

Quote:
Originally Posted by Homegrownandy View Post
I don't know if I should be naming tables or even if its possible but its working perfect now.
If, by naming, you mean bookmarking, that's certainly possible and sometimes desirable. The whole table needn't be bookmarked, either; even a bookmarked single character (e.g. an end-of-cell marker) in it would suffice.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking to copy select cells in table using dropdown list to paste to new table in another worksheet CaptainRetired Excel Programming 18 01-04-2018 07:22 PM
Paste Table From XL - Word Error - Bad Parameter dan88 Word VBA 3 06-16-2016 05:39 AM
Paste merge into word table 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 merge into word table 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 merge into word table 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

Other Forums: Access Forums

All times are GMT -7. The time now is 06:41 AM.


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