宏将不会执行我的ExportAsFixedFormat。
我一直收到“错误1004-无法保存文档...”
或
“ ExportAsFixedFormat的无效用法”
我有权访问该文件夹的位置,因为我正在另一个宏中创建该文件夹,并且在其他位置未打开。
我尝试通过多种方式将Sheet1设置为活动工作表。
我已经完成ActiveSheet.ExportAs ... 我已经将Sheet1设置为一个工作表变量,然后将该变量激活(如下面的代码所示)
我什至将变量从“文本”调整为“值”(无差异)
Sub SaveNewVersion_Excel()
'PURPOSE: Save file, if already exists add a new version indicator to
filename
Dim VersionExt As String
Dim Saved As Boolean
Dim x As Long
Dim path2 As String
Dim customer As String
Dim dateVar As String
Dim partNumber As String
Dim ws As Worksheet
Dim wb As Workbook
'ws = Workbooks("NDT_Inspection_Form").Worksheets("Sheet1")
TestStr = ""
Saved = False
x = 1
Workbooks("NDT_Inspection_Form").Activate
Set ws = Worksheets("Sheet1")
Sheets("Sheet1").Activate
customer = Sheet1.Range("B17").Text
dateVar = Format(Range("N6"), "yymmdd")
partNumber = Sheet1.Range("B19").Text
path2 = "S:\Public\NDT\FPI\Inspection Reports\Archive\" & dateVaryear &
"\" & dateVar & "\" & customer & "\"
'Version Indicator (change to liking)
VersionExt = "_x"
'Need a new version made
Do While Saved = False
'Test to see if file name already exists
If FileExist(path2 & partNumber & "_x0" & ".pdf") = False Then
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=path2 &
partNumber & "_x0" & ".pdf", Quality:=xlQualityStandard,
IncludeDocProperties:=True, IgnorePrintAreas:=False,
OpenAfterPublish:=False
Saved = True
Exit Sub
ElseIf FileExist(path2 & partNumber & VersionExt & x & ".xlsx") =
False Then
ws.ExportAsFixedFormat Type:=xlTypePDF, Filename:=path2 &
partNumber & VersionExt & x & ".pdf", Quality:=xlQualityStandard,
IncludeDocProperties:=True, IgnorePrintAreas:=False,
OpenAfterPublish:=False
Saved = True
Else
x = x + 1
End If
Loop
'Module 4 - Clears documents of all data for new document submission
Call ClearAllEntries
Exit Sub
每次都会出现两个错误之一。
当将其另存为excel文件时,它的保存效果很好,但是一旦我尝试ExportAsFixedFormat方法,它就会失败。