0

我是VBA的新手,所以为我的无知道歉。我在 Excel 2016 中有一个非常复杂的宏,我需要对其进行编辑。这与之前的讨论有关

我需要更改创建的 .pdf 的输出保存路径。现在它使用 Excel 位置作为起点 (ThisWorkbook.Path) 并保存到同一个文件夹中。

但现在它需要保存到另一个文件夹,该文件夹将位于共享 Box 驱动器上。路径将根据访问文件的人而改变。

那么我应该如何使用 Environ$ 来表示C:\Users\johnsmith \Box\etc。etc. 会改变,\Box\etc 之后的一切都会改变。等是恒定的?它使用 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"

?

4

1 回答 1

0

这只是它的外观示例:

    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"
于 2018-01-10T21:43:05.837 回答