gunsmokingman Posted February 8, 2013 Share Posted February 8, 2013 Your code only adds the User InputF.Copy P & "\" & In2.value & "_offerte.doc"Where as I replace the offerte with the User InputUserDoc = P & "\" & Replace(F1a,Left(F1a,7),In2.value)Here is how I open the rename doc, the name and path can have as manyspaces in it name and it will open. '-> Open User Input Doc Act.Run(Chr(34) & UserDoc & Chr(34)),1,FalseGood job at finishing the HTA your self Link to comment Share on other sites More sharing options...
oxb Posted February 8, 2013 Author Share Posted February 8, 2013 (edited) Your code only adds the User InputF.Copy P & "\" & In2.value & "_offerte.doc"Where as I replace the offerte with the User InputUserDoc = P & "\" & Replace(F1a,Left(F1a,7),In2.value)Here is how I open the rename doc, the name and path can have as manyspaces in it name and it will open. '-> Open User Input Doc Act.Run(Chr(34) & UserDoc & Chr(34)),1,FalseGood job at finishing the HTA your selfThanks 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 Maybe we meet again on this forum if i got something else to play around with. Edited February 8, 2013 by oxb Link to comment Share on other sites More sharing options...
jaclaz Posted February 8, 2013 Share Posted February 8, 2013 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 .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 jaclaz Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 8, 2013 Share Posted February 8, 2013 jaclaz have you learned how to read VBS script yet. Myself I can write in mutilple langauges, cmd, html, hta, vbs, Jscript, Vb.netand 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 More sharing options...
oxb Posted February 8, 2013 Author Share Posted February 8, 2013 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 .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 jaclazLoL 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 I Link to comment Share on other sites More sharing options...
jaclaz Posted February 9, 2013 Share Posted February 9, 2013 jaclaz have you learned how to read VBS script yet. Myself I can write in mutilple langauges, cmd, html, hta, vbs, Jscript, Vb.netand 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 More sharing options...
oxb Posted February 9, 2013 Author Share Posted February 9, 2013 (edited) Damnit Got a problemToday 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/139So dissapointed here at home everything worked fine even got the script to take user input to fill in the adress in the document.IAny ideas?ThanxEDIT Nevermind got it fixed stupid was running the hta locally not from nas drive Edited February 9, 2013 by oxb Link to comment Share on other sites More sharing options...
oxb Posted February 9, 2013 Author Share Posted February 9, 2013 (edited) Still one more question 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,docThe 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 fsoSet FSO = CreateObject("Scripting.FileSystemObject")Fso.Copyfile input & "_offerte.doc" , input & "_factuur.doc" Const wdReplaceAll = 2Set oWord = CreateObject("Word.Application")oWord.Visible =Trueset 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 ,,,,,,,,,,wdReplaceAllEnd WithoDoc.Save Set objFSO = CreateObject("Scripting.FileSystemObject")strScript = Wscript.ScriptFullNameobjFSO.DeleteFile(strScript) Edited February 9, 2013 by oxb Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 9, 2013 Share Posted February 9, 2013 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 More sharing options...
oxb Posted February 9, 2013 Author Share Posted February 9, 2013 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 Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 9, 2013 Share Posted February 9, 2013 Just a quick note for youIf the doc file in the same foler use For Each Obj In Fso.GetFolder(".").Files If you want to add a path to the doc For Each Obj In Fso.GetFolder("DRIVELETTER:\FOLDERNAME\ANOTHERFOLDER").Files Link to comment Share on other sites More sharing options...
oxb Posted February 9, 2013 Author Share Posted February 9, 2013 (edited) Ok So far so good The file is found the script does its magic.Now im left with another questioni 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 lineIs 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.docCD = 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 = Trueset 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 ,,,,,,,,,,wdReplaceAllEnd WithoDoc.Save oDoc.Closeset oDoc = oWord.Documents.Open (CD & Obj.name & "factuur.doc") oWord.Visible = trueSet objFSO = CreateObject("Scripting.FileSystemObject")strScript = Wscript.ScriptFullNameobjFSO.DeleteFile(strScript) End if Next Edited February 9, 2013 by oxb Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 9, 2013 Share Posted February 9, 2013 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 More sharing options...
oxb Posted February 9, 2013 Author Share Posted February 9, 2013 (edited) 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 FunctionNo 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 February 9, 2013 by oxb Link to comment Share on other sites More sharing options...
gunsmokingman Posted February 9, 2013 Share Posted February 9, 2013 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 scriptperiod. I coded it so it open the doc, then after the user closes the doc you can update itwith 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now