Solved

Can I use Word Automation to create a new document based on an existing document?

Posted on 2007-11-29
10
641 Views
Last Modified: 2008-02-01
I've built a database field that links to physical existing documents (Word, PDF, Tiff). The user can use the link to open the document, or press a print button to automatically print the document.  Details found here: http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_22960923.html

The documents are read only. The client want s me to include a boiler plate on the footer of the document when it prints that says to the effect "document only good for today: Datestamp".

Is there any way to do this? Every workstation will have Word. So one idea is I could I use Word Automation to create a new document, import the existing document into the new word document, Print the document, and close down Word without saving the new document. When I create the new document, I figure it could be based from a template that is blank except for the footer message.

How feasible is this? Any other ideas?
0
Comment
Question by:Thirt
10 Comments
 
LVL 84
ID: 20380977
Is the document the same on all workstations? Or are you pulling the document from a central location (which would make more sense to me, but then I'm not the client).

When you say they're "read only", do you mean they've been set in the Windows system as read-only files? Or they're set in Word as readonly?
0
 
LVL 4

Author Comment

by:Thirt
ID: 20381959
That's correct, the documents are stored on a network share, and the hyperlink field contains the UNC path to the physical file. And the file properties are set to read only by the Network OS.
0
 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 100 total points
ID: 20389110
Thirt,
(Hello again!)
;)

Contact the support staff:
http://www.experts-exchange.com/support.jsp

...and ask that a link to this Q be placed in the Word TA.
They might be able to provide some additional help with the Word objects
;)

JeffCoachman
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 20398256
You have posted a comment in this closed question about watermarks:
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_21655046.html

Does it answer this question, or do you need further help?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 4

Author Comment

by:Thirt
ID: 20398354
Thanks for replying. I saw that artical and wanted to know if that's something I can use in Access VBA calling the Sub print function I use to print a Word document without opening Word. Or Do I need to open the document, run the code to set the watermark, print, and then close the document. And this leads to some additional questions.

1. Can I use Word Automation to open a blank Word Document and import a TIF or PDF document?
2. Instead of a Watermark, Can I print something in the document Footer programmically?
0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 400 total points
ID: 20398688
You will have to open the document, but it can be done programatically from Access.

There are two ways to connect to another application using COM, called early and late binding. It is easier to develop using early binding, so I recommend that. The disadvantage is that version changes sometimes cause difficulties.

To use early binding, you have to set a reference in the VBA editor to the relevent library (Microsoft Word Object Library.

I have adapted the Word macro code from another question into code that can be run in another application such as Access. This is the other question:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Word/Q_21635902.html
Sub ConnectToWord()

    Dim wdApp As Word.Application

    Dim wdDoc As Word.Document

    Dim sec As Word.Section

    Dim hdr As Word.Word.HeaderFooter

    Dim sh As Word.Shape

    Dim i As Integer

    Dim shHeaders As Word.Shapes

    Dim strText As String

    

    Set wdApp = New Word.Application

    wdApp.Visible = True

    Set wdDoc = wdApp.Documents.Open("C:\MyFile\MyDoc.Doc")

    strText = "COPY"

    Set shHeaders = wdDoc.Sections(1).Headers(1).Shapes

   

    'Delete any existing watermarks

    For Each sh In shHeaders

        If InStr(sh.Name, "PowerPlusWaterMarkObject") = 1 Then

            sh.Delete

        End If

    Next sh

   

    'Add shape to headers shapes collection after selecting each header

    wdDoc.Range.Select

    For Each sec In wdDoc.Sections

        For Each hdr In sec.Headers

            If sec.Index = 1 Or hdr.LinkToPrevious = False Then

                i = i + 1

                hdr.Range.Select

                Set sh = shHeaders.AddTextEffect(msoTextEffect1, _

                    strText, "Arial", 1, False, False, 0, 0)

                sh.Name = "PowerPlusWaterMarkObject" & i

                sh.TextEffect.NormalizedHeight = False

                sh.Line.Visible = msoTrue

                sh.Line.Weight = 0.25

                sh.Line.DashStyle = msoLineSolid

                sh.Line.Style = msoLineSingle

                sh.Fill.Visible = msoFalse

                sh.Fill.Solid

                sh.Line.ForeColor.RGB = RGB(0, 0, 0)

                sh.Line.BackColor.RGB = RGB(255, 255, 255)

                sh.Fill.Transparency = 0#

                sh.Rotation = 315

                sh.LockAspectRatio = True

                sh.Height = CentimetersToPoints(6.88)

                sh.Width = CentimetersToPoints(13.77)

                sh.WrapFormat.AllowOverlap = True

                sh.WrapFormat.Side = wdWrapNone

                sh.WrapFormat.Type = 3

                sh.RelativeHorizontalPosition = _

                    wdRelativeVerticalPositionMargin

                sh.RelativeVerticalPosition = _

                    wdRelativeVerticalPositionMargin

                sh.Left = wdShapeCenter

                sh.Top = wdShapeCenter

            End If

        Next hdr

    Next sec

End Sub

Open in new window

0
 
LVL 4

Author Comment

by:Thirt
ID: 20406050
I would like to take a few steps back and see if there is an easier soluition here.

If I could get the user to update all their documents, I would train them to add a Envirment system varable in the document footer. (ie <%VarFooter%>.

Then in Access, all I need to do use update the system varable to the customer text the user wants, and print the document as I do today.

I imagine this will not be a problem in Word. But I wonder if PDF documents support system enviroment varables. But that still leaves me with TIF documents.

So does this put be back into create a new Word document on the fly? If so, How do I import the existing file I need to print?
0
 
LVL 76

Assisted Solution

by:GrahamSkan
GrahamSkan earned 400 total points
ID: 20406195
I can't tell you about PDF. I have no experience with that.

For the rest, can I ask you confirm that your requirement? As I understand it, it is to produce a single printed copy of an existing document with a watermark that might vary.
0
 
LVL 4

Author Comment

by:Thirt
ID: 20406423
The requirement is that when my Access application prints a document (Doc, PDF, TIF, PPT), a boiler plate on the footer of the document needs to display one of two options.
1. "This document only valid for today: 12/04/2004".
2. "This is a training document, not to be used for production".

There will be an option for the user to select the option to print the Training footer. If not, I have to print today's date with the message.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article will show you how to use shortcut menus in the Access run-time environment.
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now