VBSRIPT_FILE_MANIP
Sub SaveToRelativePath()
Dim relativePath As String
relativePath = ThisWorkbook.Path & "\" & ActiveWorkbook.Name
ActiveWorkbook.SaveAs Filename:=relativePath
End Sub
' Call as : replacedquotes.vbs <file1>
' Edits in place
' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
' Get input file name from command line parm, if 2 parms entered
' use second as new output file, else rewrite to input file
If (WScript.Arguments.Count > 0) Then
sInfile = WScript.Arguments(0)
Else
WScript.Echo "No filename specified."
WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
sOutfile = WScript.Arguments(1)
Else
sOutfile = sInfile
End If
' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")
' Read entire input file into a variable and close it
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
sData = oInfile.ReadAll
oInfile.Close
Set oInfile = Nothing
' Remove unwanted characters
sData = Replace(sData, """", "")
' Write file with any changes made
Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)
oOutfile.Write(sData)
oOutfile.Close
Set oOutfile = Nothing
' Cleanup and end
Set oFSO = Nothing
Wscript.Quit
' Call as cscript replace.vbs <filename> "X" "Y"
Option Explicit
Dim fso,strFilename,strSearch,strReplace,objFile,oldContent,newContent
strFilename=WScript.Arguments.Item(0)
strSearch=WScript.Arguments.Item(1)
strReplace=WScript.Arguments.Item(2)
'Does file exist?
Set fso=CreateObject("Scripting.FileSystemObject")
if fso.FileExists(strFilename)=false then
wscript.echo "file not found!"
wscript.Quit
end if
'Read file
set objFile=fso.OpenTextFile(strFilename,1)
oldContent=objFile.ReadAll
'Write file
newContent=replace(oldContent,strSearch,strReplace,1,-1,0)
set objFile=fso.OpenTextFile(strFilename,2)
objFile.Write newContent
objFile.Close
1. replace.vbs : Find and replace text in files
2. replacedquote.vbs : Find and replace any character (special ones too)
3. Saveworkbookonrelative : Save current workbook on relative folder