我是VBA的新手,所以为我的无知道歉。我在Excel 2016中有一个非常复杂的宏,需要编辑。它与this previous discussion有关
我需要更改创建的.pdf的输出保存路径。现在,它使用Excel位置作为起点(ThisWorkbook.Path),并保存到同一个文件夹中。
但是现在它需要保存到另一个文件夹中,该文件夹将位于共享的Box驱动器上。路径将根据访问文件的人而改变。
那么,我应该如何使用Environ$来表示C:\Users\johnsmith\Box\etc.等将发生变化,并且\Box\等之后的所有内容都是恒定的?它使用Excel电子表格中的值来组成新的文件名。
下面是我需要编辑的部分:
With shDetail
If llRow - 3 < 10 Then
strPDFOutPath = ThisWorkbook.Path & "\2018 Payments\0" & .Cells(llRow, 14).Value & "_" & .Cells(llRow, 3).Value & "_" & "file" & ".pdf"
Else
strPDFOutPath = ThisWorkbook.Path & "\2018 Payments\" & .Cells(llRow, 14).Value & "_" & .Cells(llRow, 3).Value & "_" & "file" & ".pdf"
End If
End With
'Save the form as new PDF file.
objAcroPDDoc.Save 1, strPDFOutPath
所以应该是
strPDFOutPath = Environ$(“USERPROFILE”) & Box\Folder1\Folder2\Folder3\0" & .Cells(llRow, 14).Value & "_" & .Cells(llRow, 3).Value & "_" & "file" & ".pdf"
Else
strPDFOutPath = Environ$(“USERPROFILE”) & Box\Folder1\Folder2\Folder3" & .Cells(llRow, 14).Value & "_" & .Cells(llRow, 3).Value & "_" & "file" & ".pdf"
发布于 2018-01-10 21:43:05
这只是一个例子,说明它可能是什么样子:
Const FILE_SUFFIX As String = "\Box\Etc\Whatever\"
Dim userPath As String
userPath = Environ("UserProfile")
strPDFOutPath = userPath & FILE_SUFFIX & & .Cells(llRow, 14).Value & "_" & .Cells(llRow, 3).Value & "_" & "file" & ".pdf"
https://stackoverflow.com/questions/48195982
复制相似问题