1

「activ」ではなく「active」という単語を検索するマクロを作成しましたが、フォルダ内の一部のファイル名に「activ」という単語が含まれている場合があります。これらを検索して名前を「アクティブ」に変更するマクロを作成して、残りのマクロが機能するようにします。私は少しずつ知っていますが、まともなコードをまとめることができないようです.

If FileName = "*activ*" then 

'also the file name is not just "activ" it maybe "activcn". 
'am i doing this right by putting the **?

FileName = replace(FileName, "activ", "active")

Else 

End if

ループを挿入して、ファイルのリストを実行し、すべてのファイル名を検索する必要があります。

実際、私は解決策を見つけました:

Dim strFile As String
Dim newPath As String

newPath = "S:\test\"

strFile = Dir(newPath & "*.*")

If strFile = "*activ*" Then

  Do While Len(strFile) > 0
    If InStr(strFile, "activ") > 0 Then
      Name strFolder & strFile As strFolder & replace(strFile, "activ", "active")
    End If
    strFile = Dir()
  Loop
Else

End If

ヘルプが必要な場合:

If strFile = "*activ*" Then

前に述べたように、ファイル名には「activ」だけでなく、「activcn」なども含まれます。

4

1 に答える 1

0

あなたの例のロジックと変数名は少し混乱しているように思えます...これがあなたの言いたいことだと思います:

Dim strFile As String
Dim strFolder As String

strFolder = "S:\test\"

strFile = Dir(newPath & "*activ*.*") ' no need to look at all files using *.*
Do While Len(strFile) > 0
    If Not strFile Like "*active*" Then 'else "active" gets replaced by "activee"
        Name strFolder & strFile _
            As strFolder & Replace(strFile, "activ", "active")
    End If
    strFile = Dir()
Loop
于 2013-11-13T08:29:13.860 に答える