Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 06-17-2015, 08:53 PM
reesjordan reesjordan is offline Error when trying to open .docx after I run a macro to copy data between tables in two documents Windows 7 32bit Error when trying to open .docx after I run a macro to copy data between tables in two documents Office 2007
Novice
Error when trying to open .docx after I run a macro to copy data between tables in two documents
 
Join Date: Jun 2015
Posts: 3
reesjordan is on a distinguished road
Default Error when trying to open .docx after I run a macro to copy data between tables in two documents

Hello Gregory,

I have two word documents, one document used content control (Test_www.docx) and the other document (Test daily.docx) has a table.

I was physically copying each cell from one table into the content controlled document. Now, thanks to some help I am using a macro to copy the data over, however whenever I save the document as a .docx I get a error:



The file "........docx cannot be opened because there are problems with the contents".

Details:
Unspecified error"
Location: Part: /word/document.xml, Line 2, Column: 275153



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) <- the (1) is for? From what I gather the '1' refers to the first ContentControl in that cell.

Things I tired (one at a time of course) >
-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.
-Updated Word

Does anyone have any suggestions on how to fix this error?

Jordan


Source code
Code:
Sub aTest()
  Dim srcDoc As Document, tgtDoc As Document
  Dim srcTable As Table, tgtTable As Table
  Dim i As Integer, strTime As String, strDesc As String
  
  Set srcDoc = Documents("Test daily (1).docx")
  Set tgtDoc = Documents("Test www.docx")
  Set srcTable = srcDoc.Tables(1)
  Set tgtTable = tgtDoc.Tables(1)
  
  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
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Please: New VBA user trying to use a macro to split Mail Merge documents. Two Run-Time Error zipit189 Word VBA 7 03-18-2015 01:13 PM
Macro to copy cell info to multiple documents Patrick Innes Word VBA 2 02-18-2015 08:38 PM
Want to change Macro to copy and paste data to new sheet Vortex69 Excel Programming 0 12-23-2014 09:53 PM
Error when trying to open .docx after I run a macro to copy data between tables in two documents Word macro: copy from different tables into one table adisl Word VBA 4 03-25-2014 02:40 AM
Error when trying to open .docx after I run a macro to copy data between tables in two documents Run-time Error 5174: Open Word Documents from Excel tinfanide Excel Programming 3 10-01-2013 07:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:57 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