-
WSreesjordan
AskWoody LoungerJune 18, 2015 at 2:31 am in reply to: VBA in Word, how to copy cells from a table into another word document that has contentcontrol #1510401Andrew,
Here is the code I have right now. Not very elegant but it works. How could I make it better?
Code:Sub Update_Wdp() Dim srcDoc As Document, tgtDoc As Document, Ddp As Document, Wdp As Document Dim srcTable As Table, tgtTable As Table, srcDate As Table, tgtDate As Table Dim i As Integer, J As Integer, strTime As String, strDesc As String ‘Check to see if two documents are open, Ddp and Wdp MsgBox (“Must have Ddp & Wdp open!” & vbNewLine & vbNewLine & “Ensure Ddp is selected, not Wdp!”) If Documents.Count 2 Then MsgBox (“Must have Ddp & Wdp open!”) End If ‘Set word document #1 to Ddp and word document #2 to Wdp Set Ddp = activeDocument If Ddp = Documents(1) Then Set Wdp = Documents(2) Else Set Wdp = Documents(1) End If ‘Set Ddp as source and Wdp target Ddp.Activate Set srcDoc = Ddp Set tgtDoc = Wdp Set srcTable = srcDoc.Tables(3) Set tgtTable = tgtDoc.Tables(3) Set srcDate = srcDoc.Tables(1) Set tgtDate = tgtDoc.Tables(1) ‘Set Date and Clear contents in Wdp for Table 3 – Project Log and format Wdp.Activate Application.ScreenUpdating = False ‘Set Date tgtDate.Cell(1, 4).Range.contentControls(1).Range.Text = srcDate.Cell(2, 4).Range.Text ‘Clear contents in Wdp for Table 3 – Project Log and format For i = 2 To tgtTable.Rows.Count tgtTable.Cell(i, 1).Range.contentControls(1).Range.Text = “HH:MM” tgtTable.Cell(i, 1).Range.Font.Color = -603937025 tgtTable.Cell(i, 2).Range.contentControls(1).Range.Text = “HH:MM” tgtTable.Cell(i, 2).Range.Font.Color = -603937025 tgtTable.Cell(i, 5).Range.contentControls(1).Range.Text = “….” tgtTable.Cell(i, 5).Range.Font.Color = -603937025 Next ‘Update contents in Wdp (Table 3 – Project Log) based on Ddp (Table 3 – Time and Details of Activities) For i = 2 To srcTable.Rows.Count strTime = srcTable.Cell(i, 1).Range.Text strTime = Left(strTime, Len(strTime) – 2) strDesc = srcTable.Cell(i, 2).Range.Text strDesc = Left(strDesc, Len(strDesc) – 2) tgtTable.Cell(i, 1).Range.contentControls(1).Range.Text = strTime tgtTable.Cell(i, 5).Range.contentControls(1).Range.Text = strDesc Next ‘Update contents in Wdp (Table 3 – Project Log) column 2 For J = 3 To srcTable.Rows.Count strTime = srcTable.Cell(J, 1).Range.Text strTime = Left(strTime, Len(strTime) – 2) tgtTable.Cell((J – 1), 2).Range.contentControls(1).Range.Text = strTime Next J ‘Update last time of the day 23:59 in Wdp (Table 3 – Project Log) column 2 For i = 2 To tgtTable.Rows.Count If tgtTable.Cell(i, 1).Range.contentControls(1).Range.Text = “23:59” Then tgtTable.Cell(i, 2).Range.contentControls(1).Range.Text = “23:59” End If Next Application.ScreenUpdating = True MsgBox (“NOTE: Content Controls don’t always accept the:” & vbNewLine & vbNewLine & Space(30) & “ENTER/Return key” & vbNewLine & vbNewLine & “Ensure all your text in the DdP is in ONE paragraph.”) End Sub
-
WSreesjordan
AskWoody LoungerJune 18, 2015 at 2:04 am in reply to: VBA in Word, how to copy cells from a table into another word document that has contentcontrol #1510396Andrew,
Thanks for you assistance. But I found the error (after hours of trial and error). My source table contained a “Enter/Return” in the paragraph, which caused the file to become corrupt. From what I gathered online, contentcontrol don’t handle the “Enter/Return” key too well.
Example of my source table:
Some text, some text.
Goes here.I changed that particular cell to one paragraph:
Some text, some text. Goes here.
Now when I save my document and try to reopen it, I no longer receive the xml/corrupt file error.
Is there a way to ignore or remove “Enter/Return” from cells?
Jordan
-
WSreesjordan
AskWoody LoungerJune 17, 2015 at 9:55 pm in reply to: VBA in Word, how to copy cells from a table into another word document that has contentcontrol #1510387Andrew,
Thanks for the quick reply it’s exactly what I required.
With a few modifications, I got everything to work on the actual documents. There is one issue.
When I save the document as a .docx and try to reopen it I get the following error:
I traced down the error (basically by commenting each line out 1 by 1) to the following line of code:
Code:tgtTable.Cell(i, 5).Range.ContentControls(1).Range.Text = strDesc
The description field contains, letters, numbers, symbols (° ‘ “) and so forth so declaring this field as a sting should be good. I tried to edit this line of code and to find a solution online but nothing seems to work.
Can you tell me what ContentControls(1)
-Dim strDesc as Variant
-Changed tgtTable.Cell(i, 5).Range.ContentControls(1).Range.Text to …. .ContentControls(2), .ContentControls(3), .ContentControls(4), .ContentControls(5), .ContentControls(i) etc.
-Ensure Word was updatedDo you have any suggestions on how to fix this error?
Jordan
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
LibreOffice 25.8. No Windows 7, 8/8.1, x86
by
Alex5723
3 hours, 33 minutes ago -
Perplexity Pro free for 12 mos for Samsung Galaxy phones
by
Patricia Grace
15 hours, 45 minutes ago -
June KB5060842 update broke DHCP server service
by
Alex5723
14 hours, 17 minutes ago -
AMD Ryzen™ Chipset Driver Release Notes 7.06.02.123
by
Alex5723
18 hours, 19 minutes ago -
Excessive security alerts
by
WSSebastian42
14 hours ago -
* CrystalDiskMark may shorten SSD/USB Memory life
by
Alex5723
1 day, 3 hours ago -
Ben’s excellent adventure with Linux
by
Ben Myers
6 minutes ago -
Seconds are back in Windows 10!
by
Susan Bradley
14 hours, 56 minutes ago -
WebBrowserPassView — Take inventory of your stored passwords
by
Deanna McElveen
3 hours, 48 minutes ago -
OS news from WWDC 2025
by
Will Fastie
1 hour, 4 minutes ago -
Need help with graphics…
by
WSBatBytes
6 hours, 6 minutes ago -
AMD : Out of Bounds (OOB) read vulnerability in TPM 2.0 CVE-2025-2884
by
Alex5723
1 day, 19 hours ago -
Totally remove or disable BitLocker
by
CWBillow
18 hours, 23 minutes ago -
Windows 10 gets 6 years of ESU?
by
n0ads
21 hours, 38 minutes ago -
Apple, Google stores still offer China-based VPNs, report says
by
Nibbled To Death By Ducks
2 days, 6 hours ago -
Search Forums only bring up my posts?
by
Deo
28 minutes ago -
Windows Spotlight broken on Enterprise and Pro for Workstations?
by
steeviebops
2 days, 17 hours ago -
Denmark wants to dump Microsoft for Linux + LibreOffice
by
Alex5723
2 days, 10 hours ago -
How to get Microsoft Defender to honor Group Policy Setting
by
Ralph
2 days, 18 hours ago -
Apple : Paragon’s iOS Mercenary Spyware Finds Journalists Target
by
Alex5723
3 days, 4 hours ago -
Music : The Rose Room – It’s Been A Long, Long Time album
by
Alex5723
3 days, 5 hours ago -
Disengage Bitlocker
by
CWBillow
2 days, 19 hours ago -
Mac Mini M2 Service Program for No Power Issue
by
Alex5723
3 days, 7 hours ago -
New Win 11 Pro Geekom Setup questions
by
Deo
32 minutes ago -
Windows 11 Insider Preview build 26200.5651 released to DEV
by
joep517
3 days, 14 hours ago -
Windows 11 Insider Preview build 26120.4441 (24H2) released to BETA
by
joep517
3 days, 14 hours ago -
iOS 26,, MacOS 26 : Create your own AI chatbot
by
Alex5723
3 days, 18 hours ago -
New PC transfer program recommendations?
by
DaveBoston
1 day, 23 hours ago -
Windows 11 Insider Preview Build 22631.5545 (23H2) released to Release Preview
by
joep517
3 days, 22 hours ago -
Windows 10 Build 19045.6029 (22H2) to Release Preview Channel
by
joep517
3 days, 22 hours ago
Recent blog posts
- Ben’s excellent adventure with Linux
- Seconds are back in Windows 10!
- WebBrowserPassView — Take inventory of your stored passwords
- OS news from WWDC 2025
- Best tools for upgrading a Windows 10 to an 11
- Master patch listing for June 10, 2025
- 24H2 may not be offered June updates
- June 2025 updates are out
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.