|
-
Dec 26th, 2010, 11:41 PM
#1
Thread Starter
Lively Member
[RESOLVED] Merging two .doc files
Hi everyone,
I wrote an application which converts .doc files into .pdf. Now I would like to add one more thing:
before converting the .doc file, which is selected by the user, I would like to add the content of an other (default) .doc file, which will not be selected by the user but the directory where the file is will be already in the code, in front of the file selected by the user. So after the two files are merged I will have the merged file converted to PDF.
I hope I have been clear enough.
Regards,
A.
-
Dec 27th, 2010, 08:06 AM
#2
Re: Merging two .doc files
Use
Code:
WordObject.Documents.ADD("1st file name with path")
and then
Code:
WordObject.Selection.InsertFile(filename:=2ndfile_FullName, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False)
-
Dec 27th, 2010, 08:26 AM
#3
Thread Starter
Lively Member
Re: Merging two .doc files
Hi Amrita.
Thanks for the reply. How should I declare "WordObject"? It keeps telling me "Name WordObject is not declared"
Thank you,
A.
-
Dec 27th, 2010, 08:29 AM
#4
Re: Merging two .doc files
Code:
Dim wordObject as Object
wordObject = CreateObject("Word.Application")
-
Dec 27th, 2010, 08:48 AM
#5
Thread Starter
Lively Member
Re: Merging two .doc files
Cool now it compiles with no errors!
Unfortunately the program does not seem working. Nothing happens after i click the button!
Here is the code:
Code:
Dim wordObject As Object
wordObject = CreateObject("Word.Application")
wordObject.Documents.ADD("C:\hello.doc")
wordObject.Selection.InsertFile(filename:=TextBox1.Text, Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False)
Thank you,
A.
-
Dec 27th, 2010, 11:51 AM
#6
Thread Starter
Lively Member
Re: Merging two .doc files
I did it by using the following code:
Code:
Dim wordObject As Object
wordObject = CreateObject("Word.Application")
wordObject.Documents.ADD(TextBox1.Text)
wordObject.Selection.InsertFile(filename:="C:\hello.doc", Range:="", ConfirmConversions:=False, Link:=False, Attachment:=False)
wordObject.activedocument.saveas("c:\hellomerged.doc")
MsgBox("ok")
Now I noticed that in the running processes there is the "WINWORD.exe" which is running in background. I need to figure out how to terminate it from the vb code.
I tried
Code:
wordObject.activedocument.close("c:\hellomerged.doc")
but doesn't work
-
Dec 27th, 2010, 01:26 PM
#7
Thread Starter
Lively Member
Re: Merging two .doc files
Solved!
I just add the following line:
Code:
wordObject.activedocument.close()
Thank you!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|