batch files.. please help me!!

Soldato
Joined
25 Oct 2002
Posts
4,198
Location
Derbyshire
Is it possible to make a .bat file to open a text file, remove old text and paste new?

At work we have 2 systems, A and B. To get data from a to b we have to copy from A, open a file with no extention (click on it then select notepad as the always open with box is greyed out) , ctrl+A, ctrl+V, save as and then open B and import.

Ive made by guessing a .bat to open the file with no extention direct into notepad, can you guys help with the rest??

Code so far :) this seems to work but i've realy no idea if its right.
Code:
C:\WINDOWS\notepad.exe "C:\work related folder\Work File"


Oh and how do you make the dos window close after its opened notepad? It closes when i close notepad but not before.
 
I don't think you can do that with a BAT file. You will want to look into a VB Script. This way you can use the FileSystemObject to open the text file then use SendKey to send the CTRL-A + CTRL-V.

Let me know if you want an example or something. :)

TrUz
 
Here you go, this should do all you need. Let me know if you need some more help. :)

Copy and past this in to a Text file and give it an extension of .vbs
Code:
' Create an instance of the FileSystemObject.
Set FileSys = CreateObject("Scripting.FileSystemObject")
' Open our Text file for writing.
Set FileTxt = FileSys.OpenTextFile("C:\Helpdesk\Test.txt", 2, True, -1)
' Create an instance of IE so we can use the Clipboard.
Set UseIE = CreateObject("InternetExplorer.Application")

' Variable to hold the Clipboard data.
Dim ClipText

' Tell IE to navigate somewhere.
UseIE.Navigate("about:blank")
' Use IE to get the Clipboard data and assign it to our variable.
ClipText = UseIE.document.parentwindow.clipboardData.GetData("text")
' Close our instance of IE.
UseIE.Quit
' Wtire the Clipboard data to our Text file.
FileTxt.Write (ClipText)
' Close our Text file.
FileTxt.Close
Thanks,

TrUz
 
Thank you very much

Which bit do i edit to add my file?


Just change C:\Helpdesk\Test.txt to C:\work related folder\Work File?
 
Tried it anyway and it works!

Fantastic mate :) gona save me about an hour a week in pointless waiting :)


Is there anyway of adding a little splash screen saying something like 'please wait'?

I work with an older gentleman (sat near me ;) ) who bangs at the link 30 times thinking its not working lol
 
The_blue said:
Is there anyway of adding a little splash screen saying something like 'please wait'?


(hope TrUz doesn't mind...)
insert this bit in the relevant section to get a progress message
----------------------
.
.
.
UseIE.Quit

MsgBox "copy started", vbInformation, "copy text ©TrUz"

' Wtire the Clipboard data to our Text file.
FileTxt.Write (ClipText)
' Close our Text file.
FileTxt.Close

MsgBox "copy done", vbInformation, "copy text ©TrUz"
.
----------------------



thanks for the script TrUz :cool:
 
Hi Chaps,

No I do not mind you tagging that bit on to the Script. User feedback from the script is good. :)

Cheers,

TrUz
 
Just dug this thread up to ask another question and noticed i never said thanks!! :eek:

Anyway



THANKS!!! ;)



My question was that if no info is in the clipboard it throws up an error (understandable) but can the error be re used to say something like 'run the macro first fool!' ?
 
You could do something like:
Code:
' Create an instance of the FileSystemObject.
Set FileSys = CreateObject("Scripting.FileSystemObject")
' Open our Text file for writing.
Set FileTxt = FileSys.OpenTextFile("C:\Helpdesk\Test.txt", 2, True, -1)
' Create an instance of IE so we can use the Clipboard.
Set UseIE = CreateObject("InternetExplorer.Application")

' Variable to hold the Clipboard data.
Dim ClipText

' Tell IE to navigate somewhere.
UseIE.Navigate("about:blank")
' Use IE to get the Clipboard data and assign it to our variable.
ClipText = UseIE.document.parentwindow.clipboardData.GetData(  "text")
' Close our instance of IE.
UseIE.Quit

If ClipText <> "" Then
    ' Wtire the Clipboard data to our Text file.
    FileTxt.Write (ClipText)
    ' Close our Text file.
    FileTxt.Close
Else
    MsgBox "Run the Macro First Muppet!!!"
End If

I have just modified my original script, you might want to re-add bitslice changes. :)

TrUz
 
Hey thanks, this is good stuff!

Roy (the older bloke) didn't run the marco taday and got a shock :D


Can you alter the icon in the warning box?
 
just replace this bit of code:
---------------
Else
MsgBox "Run the Macro First Muppet!!!", vbCritical, "copy text ©TrUz"
End If
---------------


these are the other options for the warning icon

vbCritical..........Display Critical Message icon.
vbQuestion.......Display Warning Query icon.
vbExclamation...Display Warning Message icon.
vbInformation....Display Information Message icon.

:)

.
 
Me again!!

Since you great folk are saving me so much time doing the duff stuff at work i'm gona ask for your help again.

Every day i get emailed 4 files and every day they are called the same thing (say fileA.txt, fileB.txt etc....)

We save each of the 4 files as another name (meat.txt, produce.txt, Chilled.txt, produce chill.txt) so the xl work sheets understand them.


We also get a printout of the FileA/b/c.txt sheets as backups that sit in a folder 1 month then get binned.

I want to do away with the paper copy as it's such a waste and for the 2-3 times a month we ever look at them we could print as needed.


Ok.

What i'm after is something that can copy and save with a dated name the files saved. So Meat.txt becames MEAT041206.txt and saves into a new folder on c drive. So every day i get the email, save as and run the file to create a backup.

Can this be done? and can it do all files at the same time?
 
Back
Top Bottom