【发布时间】:2020-01-13 16:25:27
【问题描述】:
我对 VBA 真的很陌生。我只粘贴了这个子的最后一部分,但如果有帮助,可以把其余的部分贴上。将不胜感激任何帮助。我已经搜索了几天,但是这个错误的大多数问题都是由路径名中的空格引起的。多谢!
此宏读取标题,然后读取打开的 Word 文档中的每个表格,然后将每一行写入htmlFile 变量。然后它运行将 HTML 文件写入保存路径的 PowerShell ps1 文件。
在较小的 Word 文档上效果很好,但是当我在较大的 Word 文档上运行它时,我得到了这个错误:
运行时错误“-2147024690 (800700ce)”:对象的方法“运行” 'IwshShell3' 失败
代码(在此位之前,Sub 中的所有内容都在读取打开的 Word 文档中的每个表并作为 HTML 代码写入htmlFile):
Sub WriteHtml()
Dim htmlFile AS String, strText As String
'
' fill htmlFile with HTML code ...
htmlFile = htmlFile & strText
Dim pwFileLocation, htmlFileLocation As String
pwFileLocation = "'O:\Docketbk\DocketToWeb\processFile.ps1'"
'htmlFileLocation = "'W:" & stringSplits(1) & "'"
htmlFileLocation = "'Q:\OIT\Web Sites\This Site\Regulatory\Docketbk\" & stringSplits(1) & "'"
fileNameFinal = Left(ActiveDocument.Name, InStrRev(ActiveDocument.Name, ".") - 1) & ".html"
Dim shell, command1
command1 = "powershell -noexit -command powershell.exe -Executionpolicy Bypass -File " & pwFileLocation & "-htmlContent ""'" & htmlFile & """' -savePath " & htmlFileLocation & " -fileName """ & fileNameFinal & """"
Set shell = CreateObject("WScript.Shell")
shell.Run command1, 1
End Sub
POWERSHELL 代码:
param(
[string] $htmlContent,
[string] $savePath,
[string] $fileName
)
$fullFilePath = $savePath + "\" + $fileName
Function CreateHtmlFile()
{
if (!(Test-Path -Path $fullFilePath)){
New-Item $fullFilePath -ItemType File
WriteHtmlFile
} else {
WriteHtmlFile
}
}
Function WriteHtmlFile()
{
Set-Content $fullFilePath $htmlContent.Replace('$DubQ','"')
}
createHtmlFile
POWERSHELL 移动代码:
param(
[string] $oldFileLocation,
[string] $newFileLocation
)
net use W: \\MYSERVERNAME\Websites\PUC\Regulatory\Docketbk
Function MoveFile
{
$moveDirectory = $oldFileLocation + "/*"
Copy-Item -Path $MoveDirectory -Destination $newFileLocation -Container -Recurse -force
}
MoveFile
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: vba powershell ms-word