【发布时间】:2018-08-02 09:35:17
【问题描述】:
这里是新的,一般是在 VBA 中。我创建了一个宏,它可以复制 excel 中单元格的内容并粘贴到 word 文档中的特定位置。仅供参考,我使用 word 中的书签来选择粘贴的确切位置。问题是复制的所有内容都会插入一行和/或段落/回车符。我找到了很多可能的解决方案,但没有一个可行,因为我在 VBA 方面缺乏经验。请帮忙!
Sub OpenWord()
Dim WordApp As Object
Dim WordDoc As Object
Dim R1 As Object
Dim R2 As Object
Set WordApp = CreateObject("Word.Application")
Set WordDoc = WordApp.Documents.Open(Filename:="C:\Users\KG\Desktop\VBA WIP\FAfile.docx")
Set R1 = WordDoc.Bookmarks("b1")
Set R2 = WordDoc.Bookmarks("b2")
WordApp.Visible = True
WordApp.Activate
Sheets("Details INPUT").Range("H4").copy
R1.Select
WordApp.Selection.PasteAndFormat Type:=wdFormatSurroundingFormattingWithEmphasis
Application.CutCopyMode = True
Sheets("Details INPUT").Range("H7").copy
R2.Select
WordApp.Selection.PasteAndFormat Type:=wdFormatSurroundingFormattingWithEmphasis
Application.CutCopyMode = True
Set WordDoc = Nothing
Set WordApp = Nothing
Set R1 = Nothing
Set R2 = Nothing
End Sub
【问题讨论】:
标签: vba excel line-breaks carriage-return