excel - 使用 excel 从 Word 创建 pdf:document.exportasfixedformat 未创建文件的扩展名
问题描述
我正在使用 Excel vba 来修改 Word 文档,然后将其另存为 pdf。它运行顺利,它会创建一个 pdf 文件,但不会创建扩展名。所以基本上问题是文件不被识别为pdf(图标不是pdf图标)并且在打开时,它会要求应用程序用来打开文件。在此文件的“扩展名”下的 Windows 资源管理器中有一个空白。
用于转换为 pdf 的代码部分是:
Dim saved_successfull As Boolean
saved_successfull = False
Dim fenetre_saveas As Object
Set fenetre_saveas = Application.FileDialog(msoFileDialogSaveAs)
With fenetre_saveas 'save as pdf
.InitialFileName = nom_complet
.Title = "Confirmer le répertoire où le pdf sera sauvegardé"
.InitialView = msoFileDialogViewList
.FilterIndex = 25
If .Show <> 0 Then
worddoc.ExportAsFixedFormat _
OutputFileName:=nom_complet, _
ExportFormat:=wdExportFormatPDF, Openafterexport:=False
saved_successfull = True
End If
End With
If saved_successfull = True Then
worddoc.Close savechanges:=False 'fermeture du doc word
WordApp.Quit
MsgBox ("Saved successfull")
Exit Sub
Else
MsgBox ("Couldn't convert in pdf")
End If
Exit Sub
所以基本上没有产生错误信息。我收到消息框(“Saved succesfull”),文件以正确的名称保存在所需的路径中。但是文件的扩展名不存在。
所以它是一个pdf,但它不会被自动识别为一个。如果我使用pdf阅读器打开它,它将被阅读。任何想法,我错过了什么?
非常感谢您提前。
解决方案
线
.InitialFileName = nom_complet
包含变量“nom_complet”。该变量需要以“.pdf”结尾。虽然它是 pdf 类型的文件名,但如果在 ".initialFileName" 中作为变量传递,则必须以 ".pdf" 结尾。
好的,这很明显,但也许其他人会遇到这个问题,所以我将答案留在这里。
推荐阅读
- angular - 如何使用 ReactiveForm 测试提交表单。表单在提交期间重新加载
- ruby-on-rails - 如何在 Rails 响应中发送虚假 JSON 数据
- php - 带有 Ajax 的 Jquery 动画发布到 php 脚本
- javascript - 在自定义“Each”中使用回调编写“地图” - JavaScript
- c# - 从 DatePicker 触发命令或触发器
- excel - Excel VBA - 查找单元格并添加到动态数组
- algorithm - 根据偏好创建调度算法
- angular - 如何在角度组件中找到树中的节点
- date - 在批处理文件中使用日期命令时错误级别不起作用
- vps - Node-red 管理页面未加载