在VBA access中运行powershell
我需要更改多个文本文件中的字符串 我已经在ACCESS VBA中编写了下面的脚本,但错误是类型不匹配在VBA access中运行powershell,vba,powershell,ms-access,Vba,Powershell,Ms Access,我需要更改多个文本文件中的字符串 我已经在ACCESS VBA中编写了下面的脚本,但错误是类型不匹配 Dim str As String str = "N=maher" Call Shell("c:\windows\system32\powershell.exe" - Command("get-content -Path e:\temptest.txt") - Replace(str, "maher", "ali")) 调用PowerShell的语法太离谱了。建议:首先让它自己从命令行运行,然
Dim str As String
str = "N=maher"
Call Shell("c:\windows\system32\powershell.exe" - Command("get-content -Path e:\temptest.txt") - Replace(str, "maher", "ali"))
调用PowerShell的语法太离谱了。建议:首先让它自己从命令行运行,然后从Access运行(一个奇怪的选择:它只会使这更复杂) 执行此操作的PowerShell脚本(
.ps1
文件)需要包含以下内容:
Get-Content -Path "E:\temptest.txt" | ForEach-Object { $_ -Replace 'maher', 'ali' } | do-something-with-the-updated-content
您需要定义:
- 您要替换的内容(您将
传入,然后为N=maher
硬编码两个字符串Replace
- 替换后如何处理字符串(
仅读取文件)Get Content
-命令(“获取内容-路径e:\tentest.txt”)。替换(“maher”,“ali”)
我不这么认为。如果我不得不猜测的话,-replace
是要在PowerShell环境中进行验证的,而不是在VBA环境中。但是OP没有告诉我们,所以没有人知道。显然是x-y问题。如果要使用VBA替换文件中的字符串,则不需要涉及PowerShell。