Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VBA access中运行powershell_Vba_Powershell_Ms Access - Fatal编程技术网

在VBA access中运行powershell

在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的语法太离谱了。建议:首先让它自己从命令行运行,然

我需要更改多个文本文件中的字符串

我已经在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的语法太离谱了。建议:首先让它自己从命令行运行,然后从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。