Jump to content

Noob needs help vbs script change text in word .doc


Recommended Posts

Your code only adds the User Input


F.Copy P & "\" & In2.value & "_offerte.doc"

Where as I replace the offerte with the User Input


UserDoc = P & "\" & Replace(F1a,Left(F1a,7),In2.value)

Here is how I open the rename doc, the name and path can have as many

spaces in it name and it will open.

 
'-> Open User Input Doc
Act.Run(Chr(34) & UserDoc & Chr(34)),1,False

Good job at finishing the HTA your self

Link to comment
Share on other sites


Your code only adds the User Input


F.Copy P & "\" & In2.value & "_offerte.doc"

Where as I replace the offerte with the User Input


UserDoc = P & "\" & Replace(F1a,Left(F1a,7),In2.value)

Here is how I open the rename doc, the name and path can have as many

spaces in it name and it will open.

 
'-> Open User Input Doc
Act.Run(Chr(34) & UserDoc & Chr(34)),1,False

Good job at finishing the HTA your self

Thanks for all the effort,

And thanks for the good job statement that means a lot coming from you.

Thanks to the others for the input i got a little wizer in scripting.

The thing is sometimes i want something automated and then i go all-in.

But it takes a long time before i have a new project, and by then i forgot most part of it.

If you see the amount of code used to do something this simple you get some more respect for coders and programmers.

We are all accustomed that the pc works when we turn it on, but really never stand stil by whats behind it all.

So respect to all of you :thumbup

Maybe we meet again on this forum if i got something else to play around with.

Edited by oxb
Link to comment
Share on other sites

If you see the amount of code used to do something this simple you get some more respect for coders and programmers.

We are all accustomed that the pc works when we turn it on, but really never stand stil by whats behind it all.

That is the initial steep of the curve, after you will get the hang of it you will probably start wondering how come that some (not necessarily all :)) programmers have this quirk for selling you trifling things as if they were the only geniuses on earth capable of doing that :ph34r: .

Seriously, I have seen guys putting together half @§§ed MS Access "custom databases" (actually no more that a few forms and reports) talking as if they were Linus Torvalds or Sergey Brin :w00t:

jaclaz

Link to comment
Share on other sites

jaclaz have you learned how to read VBS script yet. Myself I can write in mutilple langauges, cmd, html, hta, vbs, Jscript, Vb.net

and you? All self taught , unless you really want to count one semester of programmming in around 1983 when I went to college.

Link to comment
Share on other sites

If you see the amount of code used to do something this simple you get some more respect for coders and programmers.

We are all accustomed that the pc works when we turn it on, but really never stand stil by whats behind it all.

That is the initial steep of the curve, after you will get the hang of it you will probably start wondering how come that some (not necessarily all :)) programmers have this quirk for selling you trifling things as if they were the only geniuses on earth capable of doing that :ph34r: .

Seriously, I have seen guys putting together half @§§ed MS Access "custom databases" (actually no more that a few forms and reports) talking as if they were Linus Torvalds or Sergey Brin :w00t:

jaclaz

LoL Yeah i know what you mean, i am quite good as to setting up a network enviroment as a hobby.

Sometimes i have some it guy come over and i have to make corrections to his s***.

My brother in law wanted a vpn connection to his office, the reply was: not possible! you need new computers

i spend some time on it and got it to work.

Just tried to rip him off :realmad:

:hello:

I

Link to comment
Share on other sites

jaclaz have you learned how to read VBS script yet. Myself I can write in mutilple langauges, cmd, html, hta, vbs, Jscript, Vb.net

and you? All self taught , unless you really want to count one semester of programmming in around 1983 when I went to college.

Sure, reading is easy :).

Writing is another thing.

However you would be surprised by the little thingies that this old dinosaur wrote in VBA (for Excel) ;).

jaclaz

Link to comment
Share on other sites

Damnit Got a problem

Today i tried to run the script on the NAS but i believe the path is not correct.

On the pc there is a network connection to the drive (Z:)

In the script i tried to put in the networkdriveletter Z:

The script runs and gives error not finding document, the folder is not created and there are no files copied.

Do i have to fill in something like %networkdrive% or %networkpath% in line 137/139

So dissapointed here at home everything worked fine even got the script to take user input to fill in the adress in the document.

I

Any ideas?

Thanx

EDIT

Nevermind got it fixed stupid was running the hta locally not from nas drive :blushing:

Edited by oxb
Link to comment
Share on other sites

Still one more question :lol:

How can i make this script look for the .doc file and automaticly use that .doc?

This vbs wil be in the same folder as the userinput,doc

The userinput.doc name will change every time so i would like to use a wildcard like in dos *.doc but dont know how to do it in vbs.

Note that there wil be only one .doc file in the same directory as this vbs script. it wil always be named like this userinput_offerte.doc.

I wouldt like to take out the userinput just click and go.


currentDirectory = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))
input = Inputbox("Geef naam, bijv: De Groot")
dim fso
Set FSO = CreateObject("Scripting.FileSystemObject")
Fso.Copyfile input & "_offerte.doc" , input & "_factuur.doc"
Const wdReplaceAll = 2
Set oWord = CreateObject("Word.Application")
oWord.Visible =True
set oDoc = oWord.Documents.Open (currentdirectory & input & "_factuur.doc")
With oWord.Selection
.Find.Text = "Offerte:"
.Find.Replacement.Text = "factuur:"
.Find.Forward = True
.Find.MatchWholeWord = True
.Find.Execute ,,,,,,,,,,wdReplaceAll
.Find.Text = "Na eventuele accordatie stellen wij betaling per pin op prijs."
.Find.Replacement.Text = "Wij danken u voor uw opdracht, graag betaling via PIN"
.Find.Forward = True
.Find.MatchWholeWord = True
.Find.Execute ,,,,,,,,,,wdReplaceAll

End With
oDoc.Save


Set objFSO = CreateObject("Scripting.FileSystemObject")



strScript = Wscript.ScriptFullName
objFSO.DeleteFile(strScript)

Edited by oxb
Link to comment
Share on other sites

Here this will sort out the doc type , you will have to work out where to place it in your script.


Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Obj

For Each Obj In Fso.GetFolder(".").Files
If LCase(Right(Obj.Name,3)) = "doc" Then
WScript.Echo Obj.Name
End If
Next

Link to comment
Share on other sites

Here this will sort out the doc type , you will have to work out where to place it in your script.


Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Obj

For Each Obj In Fso.GetFolder(".").Files
If LCase(Right(Obj.Name,3)) = "doc" Then
WScript.Echo Obj.Name
End If
Next

Going to try this one out thanx yet again :thumbup

Link to comment
Share on other sites

Ok

So far so good

The file is found the script does its magic.

Now im left with another question

i need the file to be copied and saved as a new document but i need part of the name replaced.

What i am left with now is name_offerte.doc is copied over to name_offerte.docfactuur.doc<in one line

Is there a way to take the last part of the string in name_offerte.doc where i only get the name as a string minus _offerte.doc?

I read you can use replace function but i cant see to implement that

The tricky thing is the file needs to be opened at the end so if i rename it how do i open it if i dont know its name if the name is not always the same.(only the end part _offerte.doc, or _factuur.doc)

dont know if i make any sense but what i need is the file to be opened word replace takes place and file needs to be saved as name_factuur.doc


CD = left(WScript.ScriptFullName,(Len(WScript.ScriptFullName))-(len(WScript.ScriptName)))

Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Obj

For Each Obj In Fso.GetFolder(".").Files
If LCase(Right(Obj.Name,3)) = "doc" Then
Set FSO = CreateObject("Scripting.FileSystemObject")
Fso.Copyfile Obj.name , Obj.name & "" & "Factuur.doc"

Set oWord = CreateObject("Word.Application")
oWord.Visible = True
set oDoc = oWord.Documents.Open (CD & Obj.name & "factuur.doc")
With oWord.Selection
.Find.Text = "Offerte:"
.Find.Replacement.Text = "factuur:"
.Find.Forward = True
.Find.MatchWholeWord = True
.Find.Execute ,,,,,,,,,,wdReplaceAll
.Find.Text = "Na eventuele accordatie stellen wij betaling per pin op prijs."
.Find.Replacement.Text = "Wij danken u voor uw opdracht, graag betaling via PIN"
.Find.Forward = True
.Find.MatchWholeWord = True
.Find.Execute ,,,,,,,,,,wdReplaceAll

End With
oDoc.Save
oDoc.Close
set oDoc = oWord.Documents.Open (CD & Obj.name & "factuur.doc")
oWord.Visible = true

Set objFSO = CreateObject("Scripting.FileSystemObject")



strScript = Wscript.ScriptFullName
objFSO.DeleteFile(strScript)
End if
Next

Edited by oxb
Link to comment
Share on other sites

Have you ever thought of just adding the vbs script to the hta.

Example


Function ProcessFinished()
'-> Open User Input Doc
Act.Run(Chr(34) & UserDoc & Chr(34)),1,False
window.clearTimeout(Tm1)
window.close()
End Function


Function ProcessFinished()
'-> Open User Input Doc
Act.Run(Chr(34) & UserDoc & Chr(34)),1,True
'-> Code To Do Whatever DOC
window.clearTimeout(Tm1)
window.close()
End Function

Link to comment
Share on other sites

Have you ever thought of just adding the vbs script to the hta.

Example


Function ProcessFinished()
'-> Open User Input Doc
Act.Run(Chr(34) & UserDoc & Chr(34)),1,False
window.clearTimeout(Tm1)
window.close()
End Function


Function ProcessFinished()
'-> Open User Input Doc
Act.Run(Chr(34) & UserDoc & Chr(34)),1,True
'-> Code To Do Whatever DOC
window.clearTimeout(Tm1)
window.close()
End Function

No because it is an option to run, and it will only need to run after the offerte.doc is filled in.

There is a chance it will never be run if the order is cancelled.

Have you got any ideas how to edit the vbs so that the file is copied to name_factuur?

Greetz oscar

Edited by oxb
Link to comment
Share on other sites

No because it is an option to run, and it will only need to run after the offerte.doc is filled in.

There is a chance it will never be run if the order is cancelled.

If they cancel then it should just close every thing. What you are trying to do is illogical.

Think about it get user input give option there to cancel, after submit run the whole script

period. I coded it so it open the doc, then after the user closes the doc you can update it

with the change information. That the most simple way of doing it.


Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Obj

For Each Obj In Fso.GetFolder(".").Files
If LCase(Right(Obj.Name,3)) = "doc" And _
InStr(1,Obj.Path,"offerte",1) Then
WScript.Echo Obj.Name
End If
Next

Results on my desktop Some Test offerte.doc

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...