Looking for hired help! (Word COM)

Talk about anything
Johana
Posts: 189
Joined: 02 May 2017, 02:34

Looking for hired help! (Word COM)

13 Oct 2017, 15:28

A few days ago I posted my script to see if I could make it better and I was suggested Word Com(dom?). I tried to read about it but it felt extremly hard. Took me almost a year to know how to write a simple gui code.

So looking for someone who can help me code small script (by helping me, not by just giving it to me) with Word. The prob is: I can't send the Word document as it belongs to the animal rescue shelter I volunteer at and they are very strict.

So my idea is: I'll tell you what I want to accomplish (basically pasting variables from a GUI inside template in Word) and you can tell me what to search for that you need to help me etc.

Sounds interesting? Send me a pm :)
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Looking for hired help! (Word COM)

17 Oct 2017, 01:12

Hi.
There are definitely many ways to solve your issue.
One way I realized filling Microsoft Office Word documents is, to insert something called in german language "Textmarke" (Maybe called Bookmark in Redmond) and then fill it with AHK.
To find out, which Word command is called "Textmarke", look at the picture.
Image
Note, that you have to give individual names for your new created "Textmarke".
For my issue, I had to fill four fields in a Word document. You have to adapt this for your issue.
After creating the Word document, adapt your ahk-code:

Code: Select all

$F6::
StartFilling:
wdApp := ComObjCreate("Word.Application") 
wdApp.Visible := true
wdDoc := wdApp.Documents.Add(FileNameTmp)
wdDoc.Activate
wdDoc.Bookmarks("T_FS_1").Range.Text := Variable1
wdDoc.Bookmarks("T_FS_2").Range.Text := Variable2
wdDoc.Bookmarks("T_FS_3").Range.Text := Variable3
wdDoc.Bookmarks("T_FS_4").Range.Text := Variable4
wdDoc.SaveAs(saveFile)
wdDoc :=
wdApp :=
return

Code: Select all

; FileNameTemp has to be the path of your Word template document. It can be a doc, docx, dot or dotx suffix. I think it doesn't matter. SaveFile is the full path similar to FileNameTemp. Maybe something like this:
FileNameTmp=%TempDir%\ahk_vorlagen\Templates\Example_Textmarke.dot
SaveFile =%TempDir%\ahk_results\Result_Textmarke.doc
Maybe it seems difficult, but it isn't.
If you have questions or too much money, post it in this tread or contact me. :HeHe: :HeHe: :trollface: :trollface:
Einfach nur ein toller Typ. :mrgreen:
BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Looking for hired help! (Word COM)

17 Oct 2017, 05:27

Yep, make a snapshot of that money and post it here so he can print it out at home :thumbup:
Textmarke ? :arrow: http://www.wbrnet.info/db/5302.html
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Looking for hired help! (Word COM)

20 Oct 2017, 15:36

Hi.
I've seen your pm to me and the macro you've recorded.
When a predefined letter with letterheads and so on has to be created, normally a few words or dates are filled in.
For example, an invoice for a company. Nobody creates everytime a complete new document. Most information is static, like the letterhead and the standard terms on the backside. Only a few information has to be filled in.

You say, there were no bookmarks. Thats correct. You have to insert this bookmarks, before you try to fill them.

My english is not the best. I've thougt you have a predifined MS-Word document and you only want to fill some words in it.
In your case some dates and maybe the name of the pet, name of the owner and adress, phonenumer and so on.
  1. - First step is opening the word document and insert the bookmarks and give them individual names.
    - Second step is to save this word document as template (.dot or .dotx).
    - Third step is modifiying my example script by changing the names of the bookmarks and the paths and names of the word documents.
    - Fourth step is then executing the script.
Try first to insert one bookmark into a blank word document and try to fill this with ahk.
When this works, modify your pet shelter document.

Please post code and other information or questions only into this thread.
Don't send them with pm. Use pm only to point me, that you have added something to your thread.
Otherwise it could be difficult to follow your thread.
Einfach nur ein toller Typ. :mrgreen:

Return to “Off-topic Discussion”

Who is online

Users browsing this forum: No registered users and 64 guests