View Full Version : Solved: Combining Two Documents
mgonzalez07
09-05-2005, 04:55 PM
I need to write the code so when a user fills a form and they run the macro the content of some specific Form Text Boxes are inserted into specific form text boxes in another template. I asked something similar but it was going from Word to Excel. I'm new with VBA so I'm having trouble writing the code for Word to Word.
Anne Troy
09-05-2005, 09:56 PM
Why do you have "another" template? Why not "this" template? Could you provide sample file(s)? A lot more information would be be helpful. :)
fumei
09-06-2005, 08:37 AM
And are you talking about real templates, or documents?
MOS MASTER
09-06-2005, 10:29 AM
This seams like a design problem that could be better managed so I'd love for you to tell more about what you're trying to accomplish. :yes
mgonzalez07
09-06-2005, 02:41 PM
This is what I have for going from Word to Excel.
Option Explicit
Sub WordExcel()
Dim AppExcel As Object
Dim Wkb As Object
Set AppExcel = CreateObject("Excel.Application")
Set Wkb = AppExcel.Workbooks.Open(FileName:="C:\Documents and Settings\Compaq_Owner\Desktop\Payments.xlt")
Wkb.sheets("Sheet1").Range("B8").Value = ActiveDocument.FormFields("Text1").Result
Wkb.sheets("Sheet1").Range("B14").Value = ActiveDocument.FormFields("Text2").Result
Wkb.sheets("Sheet1").Range("B15").Value = ActiveDocument.FormFields("Text3").Result
Wkb.sheets("Sheet1").Range("B16").Value = ActiveDocument.FormFields("Text4").Result
Wkb.sheets("Sheet1").Range("D14").Value = ActiveDocument.FormFields("Text5").Result
Wkb.sheets("Sheet1").Range("B9").Value = ActiveDocument.FormFields("Text9").Result
Wkb.sheets("Sheet1").Range("B10").Value = ActiveDocument.FormFields("Text10").Result
Wkb.sheets("Sheet1").Range("D11").Value = ActiveDocument.FormFields("Text12").Result
Wkb.sheets("Sheet1").Range("F11").Value = ActiveDocument.FormFields("Text13").Result
Wkb.sheets("Sheet1").Range("B11").Value = ActiveDocument.FormFields("Text11").Result
Wkb.sheets("Sheet1").Range("B12").Value = ActiveDocument.FormFields("Text14").Result
Wkb.sheets("Sheet1").Range("C18").Value = ActiveDocument.FormFields("Text48").Result
AppExcel.Visible = True
Set Wkb = Nothing
Set AppExcel = Nothing
End Sub
I need something that does essentially the same thing but from one word document to another document.
MOS MASTER
09-06-2005, 04:04 PM
Ok I still find the request a bit odd but here's some code to do it: (Wipped up quickly)
Sub FillValue()
Dim sPath As String
Dim WordApp As New Word.Application
Dim ThisDoc As Word.Document
Dim DestDoc As Word.Document
Set ThisDoc = ThisDocument
sPath = ThisDocument.Path & Application.PathSeparator & "DocToFill.doc"
Set DestDoc = WordApp.Documents.Open(FileName:=sPath)
WordApp.Visible = False
With DestDoc
.FormFields("Text1").Result = _
ThisDoc.FormFields("Text1").Result
.Save
.Close
End With
WordApp.Quit False
Set DestDoc = Nothing
Set ThisDoc = Nothing
Set WordApp = Nothing
End Sub
It will open DocToFill.doc which is in the same directory as the document you launch the code from.
It will fill a formfield with the same name as one from the document you execute. ("Text1")
It will save: DocToFill and close it and quits the new application.
All is done with visible set to false to make sure you don't see it.
HTH, :whistle:
mgonzalez07
09-06-2005, 07:27 PM
I apologize for the odd question, but thank you for all your help.
The code works just like I wanted.
Thank you.
MOS MASTER
09-07-2005, 09:18 AM
I apologize for the odd question, but thank you for all your help.
The code works just like I wanted.
Thank you.
No problem you're most welcome! :yes
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.