excel - Excel vba 代码另存为 pdf 不再适用于 excel 365(Windows 10)
问题描述
以前在 Windows 7 (Excel 2013) 上工作的 Excel VBA 代码不再在 Windows 10 (excel 365) 上工作。
现在生成了运行时错误。
Run-time error '-2147024773 (8007007b)'
Document not saved
调试器突出显示从第一个 ActiveSheet.ExportAsFixedFormat 开始的 4 行,一直到 False。
有没有办法改变我的代码,以便在 Windows 10 / excel 365 上运行?
Workbooks("Valuation Grail.xlsm").Save
Dim mydir As String
Dim mydrive As String
'Used activeworkbook.path instead of CurDir() because activeworkbook.path does not change for the same saved workbook
mydir = ActiveWorkbook.Path
mydrive = Left(mydir, 1)
'save original wmu as 2 PDFs
Dim month_end As String
Dim generic_vg As String
Dim archived_vg As String
Dim taa_packet As String
'creates saving format for archived pdf
month_end = Format(WorksheetFunction.EoMonth(Now(), -1), "yyyymmdd")
generic_vg = mydrive & ":\01\spec_folder\01 - DATA\Valuations Report\Valuations Report.pdf"
archived_vg = mydrive & ":\01\spec_folder\01 - DATA\Valuations Report\" & month_end & "-Valuations.pdf"
taa_packet = mydrive & ":\01\spec_folder2\#Packet Assembly\TAA\" & "12 - Valuation Grail.pdf"
'Saves the generic and archived version of valuation report to spce_folder data folder
ThisWorkbook.Sheets(Array("Table", "Table_SS")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
generic_vg, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
archived_vg, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
ThisWorkbook.Sheets("Summary").Select
'saves the pe tabs to the oshea packet assembly folder
ThisWorkbook.Sheets(Array("PE_Summary", "TAA_SS")).Select
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
taa_packet, Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
False
ThisWorkbook.Sheets("Summary").Select
解决方案
ActiveWorkbokk.Path
以前返回工作簿所在的完整路径,包括驱动器映射到的字母(Z、Y、X 等)。然后我会使用mydrive
仅提取该字母以在我的文件路径中使用。这种方法不再有效。
我改变了 mydrive = "Z" 并且代码现在可以工作了。
理想情况下,我想找到一种新方法来提取该驱动器号,这样我们团队的成员就不必每次都手动更改 mydrive 变量,但这目前有效。
推荐阅读
- python-3.x - 如何用 BeautifulSoup4 解析表格并优雅地打印?
- reactjs - ReactJS - 我无法通过路由到达其他内部的组件
- jquery - 进行 AJAX API 调用的问题
- sql - SQL Server:如何基于另一个表删除
- c++ - 半随机数生成 C++
- c++ - 如何在 glRotatef 中使用 glm::mat4
- jupyter-notebook - 如何修复错误 eval:2:0: provide: not at module level
- ios - '未知类型名称 FBSDK_EXTERN' 使用 CocoaPods 和 use_frameworks 导致的构建错误
- entity-framework - Entity Framework Plus 清除单个查询的缓存
- javascript - JavaScript 抛出错误 - 没有抛出错误?摩卡测试问题