2015-10-08 40 views
0

我希望能从程序员那里得到帮助。查找 - 替换文本框和表格中包含的文本

我想要做的是翻译由软件生成的单词报告,所以我转向了宏。我已经有一个包含原始单词/短语和翻译的单词文件。

我'偷'的代码从一些论坛在线翻译,这与正常的文本很好的作品。我的问题是我想翻译的报告的文本在各种“文本框”和“表格”中。

我能够手动删除表格,但保留文字。这完全破坏了格式,但我可以处理后者。 现在,不幸的是我不能对文本框做同样的事情。没有“删除,但保留了文本框的文本”功能。

我可以给你的宏代码,通过软件和文件从获取所有翻译的单词自动生成的原始报告。

我非常感谢您的时间。

+0

请这样做:提供宏代码和样本数据。当然,你“偷取”并粘贴在这里的代码必须是免费重用的。 –

回答

0

确定。这是代码转换为普通文本。

Sub Translate() 
Dim oChanges As Document, oDoc As Document 
Dim oTable As Table 
Dim oRng As Range 
Dim rFindText As Range, rReplacement As Range 
Dim i As Long 
Dim sFname As String 
'Change the path in the line below to reflect the path of the table document 
sFname = "C:\Users\user\Desktop\Dictionary.doc" 
Set oDoc = ActiveDocument 
Set oChanges = Documents.Open(FileName:=sFname, Visible:=False) 
Set oTable = oChanges.Tables(1) 
For i = 1 To oTable.Rows.Count 
Set oRng = oDoc.Range 
Set rFindText = oTable.Cell(i, 1).Range 
rFindText.End = rFindText.End - 1 
Set rReplacement = oTable.Cell(i, 2).Range 
rReplacement.End = rReplacement.End - 1 
With oRng.Find 
     .ClearFormatting 
     .Replacement.ClearFormatting 
     Do While .Execute(findText:=rFindText, _ 
      MatchWholeWord:=True, _ 
      MatchWildcards:=False, _ 
      Forward:=True, _ 
      Wrap:=wdFindContinue) = True 
      oRng.Text = rReplacement 
     Loop 
End With 
Next i 
oChanges.Close wdDoNotSaveChanges 
End Sub 

我猜你需要看到正在翻译的文件格式,它包含了所有的表格和文本框,但它是t oo很大,我不确定是否可以以某种方式将它作为附件发送。 (对不起,这是我第一次参加这个论坛)。有任何建议吗?

非常感谢 JD