我有一个大约 200 页的 Word 文档。我从 PDF 粘贴的文本不知为何丢失了空格。我该如何修复这个问题?
答案1
这很有趣但也不容易
我真正的回答是建议您修复 PDF 导出方式的问题!
但是,这个 VBa 可能会让你开始。没有撤消,所以首先创建备份
Option Explicit
Sub DoIt()
Dim maxChars As Integer
maxChars = 30 'update for the biggest word you want to check for (max characters in the word)
Dim pos As Integer
pos = 0
Dim total As Integer
total = Len(Range.Text)
Do While (pos < Len(Range.Text))
Dim s As String
s = ""
Dim wordToUse As String
wordToUse = ""
Dim i As Integer
For i = 1 To maxChars
s = s + Mid(Range.Text, pos + i, 1)
If SpellCheck(s) = True Then
wordToUse = s
End If
Next i
pos = pos + Len(wordToUse)
Dim lef As String
Dim rig As String
lef = Trim(left(Range.Text, pos))
rig = Trim(Mid(Range.Text, pos + 1))
Range.Text = Trim(lef) + " " + Trim(Replace(rig, " ", " "))
If pos >= total Then
Exit Do
End If
Loop
End Sub
Function SpellCheck(SomeWord As String) As Boolean
'credit https://stackoverflow.com/a/10776225/1221410
SpellCheck = Application.CheckSpelling(SomeWord)
End Function
逻辑很简单 - 继续添加字符,直到找到一个有效的单词...此时,确保它不是单词的一部分(例如,存在于 l 中和)。然后在末尾添加一些空白。