我正在尝试在Microsoft Word中使用糊状并合并格式化宏。我经常从网站复制,然后从该网站粘贴到Word中。不幸的是,网站格式始终是:
文字
引用
我希望格式为:
"文本。"引用。
我的代码当前是
Sub Paste_Citation()
' Paste_Citation Macro
On Error Resume Next
Selection.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeText Text:="."
End Sub
我无法弄清楚如何a)在文本和引文之间没有段落空间,b)在文本周围放置括号。如果文本最终没有时期,则格式为" blah blah"。否则,"等等。"c)不包括文本,如果文本仅包含空格和一个段。我知道我需要对C进行IF语句,但是我对Word中的VBA并不熟悉。有人可以和我一起度过这一过程吗?
编辑#1
x = Selection.PasteAndFormat(wdFormatSurroundingFormattingWithEmphasis)
'trying to set x equal to the pasted formatted value
Dim Txt As String
Dim Cit As String
Txt = Split(x, Chr(182))
'trying to split the text based on the paragraph symbol
'I am confused on what I need to do from there
编辑#2我一直在研究它的时间更长,我认为我非常接近。我想出了如何粘贴信息并合并格式,以及如何删除段落中断。我现在的问题是,我无法弄清楚如何将其引用在第一段上,将光标带到粘贴的末端,并在结尾处添加一个期限。
Sub PasteCitation()
'Modified code from http://www.vbaexpress.com/forum/archive/index.php/t-46321.html
Application.ScreenUpdating = False
Dim Txt As Range
Set Txt = Selection.Range
Txt.PasteAndFormat (wdFormatSurroundingFormattingWithEmphasis)
With Txt.Find
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
'Replace single paragraph breaks with a space
.Text = "([!^13])([^13])([!^13])"
.Replacement.Text = "1 3"
.Execute Replace:=wdReplaceAll
End With
Application.ScreenUpdating = True
End Sub
编程的红线应该是将下载的'text'和'citation'分配给变量,例如
Dim Txt As String
Dim Cit As String
Txt = "Whatever you scraped from tre website"
Cit = "Whatever else you scraped from the web"
有了完成的成就,您可以开始操纵每个字符串,然后将它们放入您想要的位置,也许在当前选择的位置。
当您遵循此方法时,您可能会提出可以快速回答的个别问题。同时,避免使用On Error Resume Next
,而您不知道可能出现什么错误以及如何处理。