Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-11-29
10
Medium Priority
?
661 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
9 Comments
 
LVL 85
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 400 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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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
 
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 1600 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 1600 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
With its various features, Office 365 can not only help you with your day-to-day business tasks, it can also do wonders for your marketing campaign.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

773 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