Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I do copying to files including variables from inside the vbscript

Status
Not open for further replies.

ehabaziz20012001

Programmer
Jan 13, 2006
10
EG
How can I do copying to files including variables from inside the vbscript :

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"
 
where are your errors?
I'm pretty sure *.txt makes no sense here.
Code:
FSO.CopyFile &Folder &"\" &FileName &"*.txt", &Folder &"\" &FileName &".txt"
You have to enumerate those yourself. That command literally just copies files, it doesn't have context to what files are in the folder you are in.
 
File name assigned usin GetOpenFileName ONCLUDES THE PATH!!!

So when you concatenate Folder and Filename....TILT!!!

I REALLY do not understand the PROCESS of what you are attemting.

Please explain in prose sans techie language.
 
I am trying to concatenate generated text files within the Vb script .
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top