ehabaziz20012001
Programmer
How can I do copying to files including variables from inside the vbscript :
FSO.CopyFile &Folder &"\" &FileName &"*.txt", &Folder &"\" &FileName &".txt"
FSO.CopyFile &Folder &"\" &FileName &"*.txt", &Folder &"\" &FileName &".txt"
Code:
Dim oBook
Dim Sheet
Dim FileName
dim shell
Set objFiles = CreateObject("Excel.Application")
FileName = objFiles.Application.GetOpenFilename("ExcelFiles (*.xl*), *.xl*")
msgbox FileName
If FileName = False Then
Wscript.Echo"Script Error: Please select a file!"
Wscript.Quit
Else
End If
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(FileName)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile(FileName)
Folder = objFSO.GetParentFolderName(objFile)
fileName = objFSO.GetFileName(objFile)
Set oBook=WScript.CreateObject("Excel.Application")
oBook.Workbooks.Open(Folder &"\" &FileName)
MsgBox FileName
MsgBox Folder
oBook.Visible = false
oBook.DisplayAlerts = false
For Each Sheet In oBook.Worksheets
Sheet.Copy
oBook.Application.ActiveWorkbook.SaveAs Folder &"\" &FileName &"_" &Sheet.Name & ".txt",-4158, CreateBackup=False
oBook.Application.ActiveWorkbook.Close False
MsgBox FileName+Sheet.Name+".txt has been created"
Next
oBook.Application.DisplayAlerts = True
oBook.Application.ScreenUpdating = True
oBook.Workbooks.Close
oBook.DisplayAlerts = True
oBook.Quit
Set oShell = WScript.CreateObject("WSCript.shell")
DIM FSO
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.CopyFile &Folder &"\" &FileName &"*.txt", &Folder &"\" &FileName &".txt"