我目前正在编写一个子例程,允许我通过使用Excel工作表中的数据将PDF保存在文件夹中,然而,当我运行代码时,PDF在预期的文件夹中无处可寻。
下面是子程序:
(我对此非常陌生,为任何错误道歉)
Sub createfile()
'Declare worksheet
Dim ws As Worksheet
Set ws = ActiveSheet
' declare location to save file as string
Dim sStoreFile As String
sStoreFile = "L:\My Documents\ExcelTestDocument"
' declare filename variable as string
Dim sFilename As String
' declare number of files to create
Dim iFileCount As Integer
iFileCount = Range("A1").End(xlDown).Row - 1
Dim i As Integer
For i = 1 To iFileCount
' set the value of the file from spreadsheet
sFilename = ws.Range("g" & i + 1).Value
' If extension has "pdf" then save as PDF
If Right(sFilename, 3) = "pdf" Then
ws.Range("A" & iFileCount + 5).Clear
ws.Range("A" & iFileCount + 5).Value = sFilename
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=sFilename
ActiveSheet.ExportAsFixedFormat Type:=xlType
End If
Next i
MsgBox "All files have been completed"
End Sub
我希望在子例程中提到的文件夹中找到PDF文件,但即使在子例程完成后,MSG框提示我所有文件都已创建,我仍然无法找到任何文件
1条答案
按热度按时间ql3eal8s1#
您必须将sStoreFile添加到文件名: