×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
How can I do copying to files including variables from inside the vbscript :

FSO.CopyFile &Folder &"\" &FileName &"*.txt", &Folder &"\" &FileName &".txt"


CODE --> vbscript

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" 

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

where are your errors?
I'm pretty sure *.txt makes no sense here.

CODE --> vbscript

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.

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

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.

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

(OP)
I am trying to concatenate generated text files within the Vb script .
Thanks

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close