- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
背景 :
在 StackOverflow 的帮助下,我成功地找到了一种使用 VBA 将特定内容(文本、表格和图表)从 Excel 复制到带有书签的 Word 模板的方法。保存时,我不想要 .docx 格式,而是想将其导出为 .pdf。我尝试使用 ExportAsFixedFormat 和 ExportAsFixedFormat2 并且能够成功导出它。
问题 :
这个 .pdf 文件上的内容被导出为图像(我猜)。我无法突出显示或复制文件中的文本。我做错了什么,我该如何解决? (仅供引用,pdf 上的内容复制设置为“允许”)
我目前正在使用 ActiveDocument.ExportAsFixedFormat2 SaveName, wdExportFormatPDF, , wdExportOptimizeForPrint
并尝试过其他变量。
任何帮助将不胜感激。
代码:
Option Explicit
Sub ExportFile()
Dim wrdApp As Word.Application
Dim WrdDoc As Word.Document
Dim WrdRng As Word.Range
Dim WrdShp As Word.InlineShape
Dim SaveName As String
Dim ChrObj As ChartObject
Set wrdApp = New Word.Application
'wrdApp.Visible = True
'wrdApp.Activate
With wrdApp
.Documents.Add Environ("UserProfile") & "\Desktop\Template.dotx"
With .Selection
Range("XEX771").Copy
.GoTo What:=-1, Name:="Bookmark1"
.PasteSpecial xlPasteValues
.GoTo What:=-1, Name:="Bookmark2"
Range("AG696", Range("AG696").End(xlDown).End(xlToRight)).Copy
Application.Wait Now() + #12:00:02 AM#
.PasteExcelTable True, False, False
.GoTo What:=-1, Name:="Bookmark3"
Range("F26", Range("F26").End(xlDown).End(xlToRight)).Copy
Application.Wait Now() + #12:00:02 AM#
.PasteExcelTable True, False, False
.GoTo What:=-1, Name:="Bookmark4"
Range("XEO5").Copy
.PasteSpecial xlPasteValues
.GoTo What:=-1, Name:="Bookmark5"
Range("K26", Range("K26").End(xlDown).End(xlToRight)).Copy
Application.Wait Now() + #12:00:02 AM#
.PasteExcelTable True, False, False
End With
Set ChrObj = ActiveSheet.ChartObjects(1)
ChrObj.Chart.ChartArea.Copy
Application.Wait Now() + #12:00:02 AM#
.Selection.GoTo What:=-1, Name:="Bookmark6"
.Selection.PasteSpecial DataType:=wdPasteMetafilePicture, Placement:=wdInLine
Set ChrObj = ActiveSheet.ChartObjects(2)
ChrObj.Chart.ChartArea.Copy
Application.Wait Now() + #12:00:02 AM#
.Selection.GoTo What:=-1, Name:="Bookmark7"
.Selection.PasteSpecial DataType:=wdPasteMetafilePicture, Placement:=wdInLine
Set ChrObj = ActiveSheet.ChartObjects(3)
ChrObj.Chart.ChartArea.Copy
Application.Wait Now() + #12:00:02 AM#
.Selection.GoTo What:=-1, Name:="Bookmark8"
.Selection.PasteSpecial DataType:=wdPasteMetafilePicture, Placement:=wdInLine
SaveName = Environ("UserProfile") & "\Desktop\FileName.pdf"
.ActiveDocument.ExportAsFixedFormat2 SaveName, wdExportFormatPDF, , wdExportOptimizeForPrint
End With
wrdApp.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
wrdApp.Quit
Set wrdApp = Nothing
End Sub
最佳答案
使用 Selection 效率非常低 - 这也可能有助于解释为什么您在代码中插入了如此多的延迟。您还有许多不必要的 .Goto 和复制/粘贴操作。尝试:
Sub ExportFile()
Dim wrdApp As New Word.Application, WrdDoc As Word.Document
Dim WrdRng As Word.Range, WrdShp As Word.InlineShape
Dim xlSheet As Excel.Worksheet: Set xlSheet = ActiveSheet
With wrdApp
.Visible = False
Set WrdDoc = .Documents.Add(Environ("UserProfile") & "\Desktop\Template.dotx")
With WrdDoc
.Bookmarks("Bookmark1").Range.Text = xlSheet.Range("XEX771").Text
xlSheet.Range("AG696", Range("AG696").End(xlDown).End(xlToRight)).Copy
.Bookmarks("Bookmark2").Range.PasteExcelTable True, False, False
xlSheet.Range("F26", Range("F26").End(xlDown).End(xlToRight)).Copy
.Bookmarks("Bookmark3").Range.PasteExcelTable True, False, False
.Bookmarks("Bookmark4").Range.Text = xlSheet.Range("XEO5").Text
xlSheet.Range("K26", Range("K26").End(xlDown).End(xlToRight)).Copy
.Bookmarks("Bookmark5").Range.PasteExcelTable True, False, False
xlSheet.ChartObjects(1).Chart.ChartArea.Copy
.Bookmarks("Bookmark6").Range.PasteSpecial DataType:=wdPasteMetafilePicture, Placement:=wdInLine
xlSheet.ChartObjects(2).Chart.ChartArea.Copy
.Bookmarks("Bookmark7").Range.PasteSpecial DataType:=wdPasteMetafilePicture, Placement:=wdInLine
xlSheet.ChartObjects(3).Chart.ChartArea.Copy
.Bookmarks("Bookmark8").Range.PasteSpecial DataType:=wdPasteMetafilePicture, Placement:=wdInLine
.SaveAs FileName:=Environ("UserProfile") & "\Desktop\FileName.pdf", _
FileFormat:=wdFormatPDF, AddToRecentFiles:=False
.Close False
End With
.Quit
End With
Set WrdDoc = Nothing: Set wrdApp = Nothing: Set xlSheet = Nothing
End Sub
关于Excel 到 Word 到 PDF 使用 VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66672973/
我想标记一个字符串,例如 Best Beat Makers,以几乎类似于 NGram 的方式为每个单词生成标记,例如: IN: "Best Beat Makers" OUT: ["Best", "B
这个问题在这里已经有了答案: Is there a way to word-wrap long words in a div? (6 个答案) 关闭 7 年前。
我想编写一个 Python 代码来检查字符串是否包含类似于以下内容的内容: 'word.Word' => 将其替换为 'word.\nWord'。 smallLetter.capitalLetter
我想编写一个 Python 代码来检查字符串是否包含类似于以下内容的内容: 'word.Word' => 将其替换为 'word.\nWord'。 smallLetter.capitalLetter
我有以下正则表达式: ^--([\w|-]+) 我想匹配 --word --no-word 但不是: ---word ----word 最佳答案 将表情更改为 ^--(\w[-\w]*) 这需要在两个
在我的加载项中,我需要为每个打开的文档创建一个任务 Pane 。在加载项的启动方法中,我订阅了 ApplicationEvents4_Event.NewDocument 和 Application.D
我使用 word javascript api 开发了一个 word 插件。我的文档 .docx 文件在服务器上,我需要在加载项中单击按钮打开该 .docx 文档作为新的 Word 文档。 请指导我如
我需要在某个地方修复一些 CSS,因为我的文本没有环绕,如果它是一个非常长的单词,它会无限期地继续下去。 在大多数情况下,我在我的 CSS 文件中尝试了 word-wrap: break-word;
这个问题在这里已经有了答案: What is the difference between "word-break: break-all" versus "word-wrap: break-word
这个问题在这里已经有了答案: What is the differect between word-wrap and overflow-wrap? [duplicate] (1 个回答) Is t
问题详细描述如下: 给定两个单词(beginWord 和 endWord)和字典的单词列表,找出是否存在从 beginWord 到 endWord 的转换序列,这样: 一次只能更改一个字母 每个转换后
我以前没有使用过邮件合并字段,我发现的所有内容都要求您在能够插入合并字段之前选择一个数据源。我想要做的就是将字段放在 word 文档上,并且在代码使用它之前不要将其合并。我基本上是在创建文档模板。这在
将此代码放置在ThisDocument_Startup之外的Word文档级VSTO解决方案中的某个位置(创建带单击事件的功能区按钮): int zero = 0; int divideByZero =
有没有办法在没有加载项的情况下启动 MS Word(仅此实例)?我只能找到一种方法来完全禁用加载项。 最佳答案 来自Word command line switches documentation ,
有没有办法在没有加载项的情况下启动 MS Word(仅此实例)?我只找到一种方法来完全禁用加载项。 最佳答案 来自Word command line switches documentation ,您
当使用 URI 方案从网页上托管的 word 模板打开新文档时不起作用。 https://msdn.microsoft.com/en-us/library/office/dn906146.aspx 这
我的问题: overflow-wrap: break-word 和 word-break: break-word 有区别吗? 非重复: 这里有一些现有的问题,乍一看可能是重复的,但实际上不是。 Wha
我希望使用 WordNet 从一组基本术语中寻找相似术语的集合。 例如,单词'discouraged' - 潜在的同义词可能是:daunted, glum, deterred, pessimistic
部署 Word Add in 时,发布没有错误。复制文件后出现以下错误。 我没有太多事情要做。这是堆栈跟踪。 ************** Exception Text **************
我需要一个 Java 正则表达式来匹配除某个单词之外的任何单词,同时包含另一个单词。 例如字符串中不能包含Apple,但必须有Peach。 Apple and Peach - Not match Pe
我是一名优秀的程序员,十分优秀!