Jump to content

Please, can anyone help me with editing a .doc file?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
sinjan

sinjan

    Newbie

  • Members
  • Pip
  • 3 posts
I have a problem with some vba programming, and unfortunately I am not to known with vba syntax. Therefore I would be extremely grateful if someone could please help me.

My problem is the following; I want to make a vba script in notepad that first reads three lines in a my_text.txt file. The first line will be a destination on the hard drive, the second line the name of the my_document.doc file I want to edit, and the third line is a project number. I guess all of these should be saved as strings in variables in vba.

Then in the rest of the script I want to edit my_document.doc file at the destination given in my_text.txt file. I just want the script to scan thru my_document.doc file and find where it says “xxx” or “xxxx” and change it to the project number given in my_text.txt file. Then at last the program should output the edited document and replace the old one.
The word document is of type “Microsoft Office Word 97 – 2003”.
Is this possible to do in vba?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
First, VBA only runs in Microsoft Office products. You cannot make it in notepad.

Second, once you replace the old .doc file, you won't have "xxx" or "xxxx" to replace ever again.

Third, it sounds like you're trying to do something along the lines of a mail merge.

Ultimately, the question is: what are you trying to accomplish? All the things you've stated don't make a lot of sense, out of context.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
sinjan

sinjan

    Newbie

  • Members
  • Pip
  • 3 posts
Okey, I will try en explaine it more properly.

The thing is, I got a task at work where I am suposed to write a program that moves a bunch of .doc documents, edits the filenames, and changes where it says "xxx" in the document text to a given projectnumber. So far I have programed the part that handles the moving of the files, and the editing of filenames. This I have done in Python. When it comes to the editing of the document text I am struggeling to get python to do it. It seems like it's to much encryption in the ms word documents. Now comes the part I am seeking help on.
I was thinking that I could write a VBA script that handles the editing of the document text. Since I already have written the part that handles the moving of the files in python, I thougt I could make Python write a .txt file with folowing;
Destination of file that needs editing,
Filename,
And a project number that should replace "xxx" in the document text.
Then I thought I could make Python call the vba program(which I am asking for help on). The vba program should then read "destination"(of the file that needs editing), "filename"(of document that needs editing), and "project number", which all are given in the .txt file created by python. Last, I want the vba program to edit the "filename".doc given in the .txt file by replacing "xxx" with the projectnumber.
Why I thought the vba script could be written in notepad, is because I was thinking that I could save it as a "my_vbscriptname.vbs" file. I think it would be easier to get python write the .txt file, then run "my_vbscriptname.vbs" for every document.

Please tell me if it is still unclear.

Thank you




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users