我有将数据发送到Word模板的Excel VBA代码(保存docx和pdf文件)。 然后,代码通过Outlook通过电子邮件发送pdf。
这一切都可以在我的本地驱动器上完美运行,但是打开,检查和保存文件夹和文件以共享点让我感到头疼。我花了数小时进行搜索和实验。...似乎有一些相互冲突的端口(主要在其他论坛上)。
当然我不是一个人。...
在我的本地驱动器上有效的代码是:
thefilepath = Application.ActiveWorkbook.Path
Set wrdDoc = wrdApp.Documents.Open(thefilepath & "\Letter Template.docx", ReadOnly:=True)
strFolderPath = thefilepath & "\Results"
CheckDir (strFolderPath)
<Run code>
wrdDoc.SaveAs thefilepath & "\Results\" & thefilename & ".doc"
wrdDoc.ExportAsFixedFormat OutputFileName:=thefilepath & "\Results\" & thefilename & ".pdf", ExportFormat:=wdExportFormatPDF
Function CheckDir(Path As String)
If Dir(Path, vbDirectory) = "" Then
MkDir (Path)
End If
End Function
问题...
文件路径不正确.....返回“ C:\ Users \ sf \ PP \ WIP \ a宏”
我正在努力创建“结果”子文件夹
Docx和PDF命名给我错误。
我的excel文件位于
thisdir = https://pplanners.sharepoint.com/sites/PP/Shared Documents/PP WIP/a Macros
我想将我的docx和pdf文件保存到thisdir和“ / results”即。
resultsdir = https://pplanners.sharepoint.com/sites/PP/Shared Documents/PP WIP/a Macros/results
所以要测试结果子目录是否存在,我已经尝试过......
If Dir("/pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/results", vbDirectory) = "" Then
If Dir("//pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/results", vbDirectory) = "" Then
If Dir("https://pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/results", vbDirectory) = "" Then
但是似乎没有任何作用
类似地,对于MkDir,我尝试了
MkDir "https://pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/Results"
MkDir "//pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/Results"
MkDir "/pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/Results"
MkDir "https://pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/Results"
MkDir "//pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/Results"
MkDir "/pplanners.sharepoint.com/sites/PP/Shared%20Documents/PP%20WIP/a%20Macros/Results"
到目前为止,我用来调整名称的便捷代码是:
tr = ThisWorkbook.Path
tr2 = Replace(Replace(tr, "http:", ""), "/", "\")
tr3 = Replace(tr2, " ", "%20")
希望对使用Sharepoint进行文件和文件夹管理进行一些讨论。