Greetings,
I was using this code and it worked perfectly. However, the organization is going to Office 360 and I decided to use Notepad (Windows 7 to windows 10)
;Open Word
wdApp := ComObjCreate("Word.Application")
wdApp.Visible := true
wdDoc := wdApp.Documents.Open(Str3)
;Replace Strings in the narrative
wdDoc.Content.Find.Execute("GVFacing",0,0,0,0,0,1,1,0,GVFacing,2)
wdDoc.Content.Find.Execute("GVPosition",0,0,0,0,0,1,1,0,GVPosition,2)
wdDoc.Content.Find.Execute("GVMilleage",0,0,0,0,0,1,1,0,GVMilleage,2)
wdDoc.Content.Find.Execute("GVCondition",0,0,0,0,0,1,1,0,GVCondition,2)
wdDoc.Content.Find.Execute("GVValue",0,0,0,0,0,1,1,0,GVValue,2)
;Copy all text then close without saving
wdApp.Selection.WholeStory
wdApp.Selection.Copy
wdApp.Quit(0)
I have been trying and I cannot make it work. May someone please how I can do what that code does in Microsoft Notepad?
Thank you
Some help to go from MS Word to Notepad
Re: Some help to go from MS Word to Notepad
No one can help?
Re: Some help to go from MS Word to Notepad
I don't know what your code is exactly doing in Word, but Notepad has no COM interface like Word for automating, so perhaps you explain what your exact goal is, so that people can think about possible workarounds... (what is the input and the desired output ?!)
Re: Some help to go from MS Word to Notepad
Unsure what you want to do?
Word contains formatted text, while Notepad essentially contains plain text (a big difference - in a way)
Word contains formatted text, while Notepad essentially contains plain text (a big difference - in a way)
Re: Some help to go from MS Word to Notepad
Here is what the code does:
1 - It open MS Word with a Ms Word document (wdDoc := wdApp.Documents.Open(Str3) Str3 is the path\name of the document
2 - I replace text strings () with text that I passed as parameters. For example, I replace the text GVFacing in the document with the content of the string variable GVFacing.
It works perfectly. However, our organization is going Office 360 that is web based and I cannot use it. I thought to use Notepad that is standard on all windows. I cannot install any software. I have to use what the organization is using. Would it work with wordpad?
Thank you
1 - It open MS Word with a Ms Word document (wdDoc := wdApp.Documents.Open(Str3) Str3 is the path\name of the document
2 - I replace text strings () with text that I passed as parameters. For example, I replace the text GVFacing in the document with the content of the string variable GVFacing.
It works perfectly. However, our organization is going Office 360 that is web based and I cannot use it. I thought to use Notepad that is standard on all windows. I cannot install any software. I have to use what the organization is using. Would it work with wordpad?
Thank you
Re: Some help to go from MS Word to Notepad
You can manipulate pure text files directly via AHK (different string functions, including RegEx functions), without the need for Notepad which doesn't support automation like MS Word. But people can probably help better, if you show some example input (text) and the intended output...
But you are saying MS Word documents... these are not pure text files by default. So, this could cause problems or - at least - additional work. Are these documents available in text format, too, or do you need to preserve any formatting?? Perhaps RTF (Rich Text Format) is an option.
Wordpad is also without COM support, afaik (?). So opening and manipulating it in Wordpad would probably introduce additional error sources. Perhaps there is something possible with the Acc.ahk library, but I have no real experience with that.
I think, the best option would be pure text files and then processing them with AHK directly, but it probably depends on the specific requirements that we don't know. Like I said before, example data would be helpful (just the structure; of course, you should anonymize any company data) - but not without information about the possible file formats and formatting requirements.
But you are saying MS Word documents... these are not pure text files by default. So, this could cause problems or - at least - additional work. Are these documents available in text format, too, or do you need to preserve any formatting?? Perhaps RTF (Rich Text Format) is an option.
Wordpad is also without COM support, afaik (?). So opening and manipulating it in Wordpad would probably introduce additional error sources. Perhaps there is something possible with the Acc.ahk library, but I have no real experience with that.
I think, the best option would be pure text files and then processing them with AHK directly, but it probably depends on the specific requirements that we don't know. Like I said before, example data would be helpful (just the structure; of course, you should anonymize any company data) - but not without information about the possible file formats and formatting requirements.
Re: Some help to go from MS Word to Notepad
The notepad text file is a "clean" text file.
No problem reading the file with AHK. ( eg. with FileRead)
Then it is possible to "manipulate" the text in the way you want in AHK. (With RegEx - for example)
And at the end save the changes with FileAppend Don't forget to delete the existing file - if it exist with FileDelete, , much like this .:
No problem reading the file with AHK. ( eg. with FileRead)
Then it is possible to "manipulate" the text in the way you want in AHK. (With RegEx - for example)
And at the end save the changes with FileAppend Don't forget to delete the existing file - if it exist with FileDelete, , much like this .:
Code: Select all
LogFil = ????.txt
IfExist %Logfil%
{ FileDelete %Logfil%
If ErrorLevel
{ MsgBox Maybe the file %Logfil% is locked, and could not be deleted. `nThis program ends!
MsgBox ,,, Program Ends, 1
ExitApp
}
}
Re: Some help to go from MS Word to Notepad
The file format has no importance because I copy the text.
My code select the final text, copy it into the clipboard then close without saving:
wdApp.Selection.WholeStory
wdApp.Selection.Copy
wdApp.Quit(0)
I used that solution because it was the easiest way to do what I wanted. At first, opening with the simple ahk function and using click and send functions. The code I published in my first post was the final code that someone showed me that was better than mine.
Thank you
My code select the final text, copy it into the clipboard then close without saving:
wdApp.Selection.WholeStory
wdApp.Selection.Copy
wdApp.Quit(0)
I used that solution because it was the easiest way to do what I wanted. At first, opening with the simple ahk function and using click and send functions. The code I published in my first post was the final code that someone showed me that was better than mine.
Thank you
Re: Some help to go from MS Word to Notepad
I did some research and found out that I can convert all my word files to text files then use this code:
FileRead, Filetext, Str3
StringReplace, NewFiletext, Filetext, GVFacing, "GVFacing", All
Clipboard := NewFiletext
I just need to text it a little bit later.
Thank you
FileRead, Filetext, Str3
StringReplace, NewFiletext, Filetext, GVFacing, "GVFacing", All
Clipboard := NewFiletext
I just need to text it a little bit later.
Thank you
Re: Some help to go from MS Word to Notepad
You are welcome!
Good luck!
Good luck!
Re: Some help to go from MS Word to Notepad
I have a question. I still was not able to test it. But here what I think I can do. Is there a way to do that more elegantly? I think I am missing something. Here is what I plan to do:
FileRead, Filetext, Str3
StringReplace, NewFiletext, Filetext, GVFacing, "GVFacing", All
StringReplace, NewFiletext1, NewFiletext, GVMilleage, "GVMilleage", All
StringReplace, NewFiletext2, NewFiletext1, GVCondition, "GVCondition", All
Clipboard := NewFiletext2
Thank you
FileRead, Filetext, Str3
StringReplace, NewFiletext, Filetext, GVFacing, "GVFacing", All
StringReplace, NewFiletext1, NewFiletext, GVMilleage, "GVMilleage", All
StringReplace, NewFiletext2, NewFiletext1, GVCondition, "GVCondition", All
Clipboard := NewFiletext2
Thank you
Re: Some help to go from MS Word to Notepad
Greetings,
For those who may want a solution. I got one finally
str3:="c:\templates\file1.txt"
FileRead, Filetext, %Str3%
StringReplace, NewFiletext, Filetext, GVFacing, 1234, All
StringReplace, NewFiletext, NewFiletext, GVMilleage, ABCD, All
StringReplace, NewFiletext, NewFiletext, GVCondition, efgh, All
Clipboard := NewFiletext
It works and no need to have multiple variable to hold the document.
Thank you all for your help.
For those who may want a solution. I got one finally
str3:="c:\templates\file1.txt"
FileRead, Filetext, %Str3%
StringReplace, NewFiletext, Filetext, GVFacing, 1234, All
StringReplace, NewFiletext, NewFiletext, GVMilleage, ABCD, All
StringReplace, NewFiletext, NewFiletext, GVCondition, efgh, All
Clipboard := NewFiletext
It works and no need to have multiple variable to hold the document.
Thank you all for your help.
Who is online
Users browsing this forum: Araphen and 309 guests