-
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
-
Win 11 24H2 June 2025 Update breaks WIFI
by
dportenlanger
2 hours, 7 minutes ago -
Update from WinPro 10 v. 1511 on T460p?
by
CatoRenasci
2 hours, 5 minutes ago -
System Restore and Updates Paused
by
veteran
4 hours, 38 minutes ago -
Windows 10/11 clock app
by
Kathy Stevens
54 minutes ago -
Turn off right-click draw
by
Charles Billow
7 hours, 52 minutes ago -
Introducing ChromeOS M137 to The Stable Channel
by
Alex5723
11 hours, 23 minutes ago -
Brian Wilson (The Beach Boys) R.I.P
by
Alex5723
26 minutes ago -
Master patch listing for June 10, 2025
by
Susan Bradley
13 hours ago -
Suggestions for New All in One Printer and a Photo Printer Windows 10
by
Win7and10
5 hours, 1 minute ago -
Purchasing New Printer. Uninstall old Printer Software First?
by
Win7and10
19 hours, 1 minute ago -
KB5060842 Issue (Minor)
by
AC641
23 hours, 34 minutes ago -
EchoLeak : Zero Click M365 Copilot leak sensitive information
by
Alex5723
1 day, 2 hours ago -
24H2 may not be offered June updates
by
Susan Bradley
44 minutes ago -
Acronis : Tracking Chaos RAT’s evolution (Windows, Linux)
by
Alex5723
1 day, 14 hours ago -
June 2025 updates are out
by
Susan Bradley
2 hours, 58 minutes ago -
Mozilla shutting Deep Fake Detector
by
Alex5723
2 days, 5 hours ago -
Windows-Maintenance-Tool (.bat)
by
Alex5723
1 day, 14 hours ago -
Windows 11 Insider Preview build 26200.5641 released to DEV
by
joep517
2 days, 7 hours ago -
Windows 11 Insider Preview build 26120.4250 (24H2) released to BETA
by
joep517
2 days, 8 hours ago -
Install Office 365 Outlook classic on new Win11 machine
by
WSrcull999
2 days, 7 hours ago -
win 10 to win 11 with cpu/mb replacement
by
aquatarkus
1 day, 23 hours ago -
re-install Windows Security
by
CWBillow
2 days, 11 hours ago -
WWDC 2025 Recap: All of Apple’s NEW Features in 10 Minutes!
by
Alex5723
2 days, 14 hours ago -
macOS Tahoe 26
by
Alex5723
2 days, 9 hours ago -
Migrating from win10 to win11, instructions coming?
by
astro46
22 minutes ago -
Device Eligibility for Apple 2026 Operating Systems due this Fall
by
PKCano
1 day, 23 hours ago -
Recommended watching : Mountainhead movie
by
Alex5723
2 days ago -
End of support for Windows 10
by
Old enough to know better
11 minutes ago -
What goes on inside an LLM
by
Michael Covington
11 minutes ago -
The risk of remote access
by
Susan Bradley
14 hours, 14 minutes ago
Recent blog posts
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.