Solved

Word setting by using macros for printing copy

Posted on 2009-07-10
7
280 Views
Last Modified: 2012-08-14
Hi,
A customer letter is written als word file. This file contents a macro that will be automatically activated by printhng the original letter and starts the following steps:
1) prepare the printing of a letter copy
2) cover the text field showing  the adressee of the original letter with a text field showing the adressee of the copy letter.

This process runs without any problems by many users. They write the original letter. The addressee of the letter copy will be given to the macro als parameter. The users print the original letter and the letter copy will automatically printed with the addressee of the copy in the right letter position.

By one user the text field "addressee of the original letter" will not be covered by the text field "addressee of letter copy" but only pulled down. Therefore you have 2 adressees on the print of the letter copy.

How can I change the word settings of this user without changing the ones of the other users? Or can I change anything directly in the macro code making sure that the text fields have a definite position on the document?

Please find attached the macro code.

Many thanks in advance and have a nice day!

isaf


Sub Wasserzeichen(bolStandard As Boolean)
 

Dim bolGesperrt As Boolean

bolGesperrt = False
 

  If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then

        ActiveDocument.Unprotect

        bolGesperrt = True

   End If
 
 

ActiveDocument.Bookmarks.Add "_InMacro_"
 

Selection.HomeKey Unit:=wdStory
 
 

If bolStandard Then

    Application.PrintOut

Else

    With Dialogs(wdDialogFilePrint)

    .Show

    End With

End If
 

'Start hier

If ActiveDocument.CustomDocumentProperties("VM_OriginalBrief") = "False" Then

    

    Dim strVermittlerNamenAdresse As String

    strVermittlerNamenAdresse = "Adressee of letter copy"

    

    

    Dim objShape2 As Word.Shape

    Set objShape2 = ActiveDocument.Shapes.AddTextbox( _

    Orientation:=msoTextOrientationHorizontal, _

    Left:=10, _

    Top:=10, _

    Width:=10, _

    Height:=10, _

    Anchor:=Selection.Paragraphs(1).Range)
 

    With objShape2

    .LockAnchor = True
 

    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage

    .RelativeVerticalPosition = wdRelativeVerticalPositionPage
 

    .LockAspectRatio = False

    .Top = CentimetersToPoints(5)

    .Left = CentimetersToPoints(2)

    .Width = CentimetersToPoints(12)

    .Height = CentimetersToPoints(3.5)

    

    

    .Line.ForeColor.RGB = RGB(255, 255, 255)

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

    

    

    .TextFrame.TextRange.Font.Name = "Arial"

    .TextFrame.TextRange.Font.Size = 12
 

    

    .TextFrame.TextRange.Text = strVermittlerNamenAdresse

    

    End With

    

    'does not concern the problem

    Dim strText As String

    Dim strEmpfaengerNamenOriginal As String

    

    If ActiveDocument.CustomDocumentProperties("Schreiben_an") = "AN" Then

        strEmpfaengerNamenOriginal = ActiveDocument.CustomDocumentProperties("Ausfertigung_KopieName")

        strText = "Diese Ausfertigung für die versicherte Person" + vbCrLf + "wurde gesendet an: " + strEmpfaengerNamenOriginal '+ "."

    ElseIf ActiveDocument.CustomDocumentProperties("Schreiben_an") = "Hinterbliebene" Then

        strEmpfaengerNamenOriginal = ActiveDocument.CustomDocumentProperties("Ausfertigung_KopieName")

        strText = "Diese Ausfertigung für die hinterbliebene Person" + vbCrLf + "wurde gesendet an: " + strEmpfaengerNamenOriginal '+ "."

    Else

        strEmpfaengerNamenOriginal = ActiveDocument.CustomDocumentProperties("Original_KopieName")

        strText = "Das Original wurde gesendet an:" + vbCrLf + strEmpfaengerNamenOriginal '+ "."

    End If

    

    

    Dim objShape3 As Word.Shape

    Set objShape3 = ActiveDocument.Shapes.AddTextbox( _

    Orientation:=msoTextOrientationHorizontal, _

    Left:=10, _

    Top:=10, _

    Width:=10, _

    Height:=10, _

    Anchor:=Selection.Paragraphs(1).Range)
 

    With objShape3

    .LockAnchor = True
 

    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage

    .RelativeVerticalPosition = wdRelativeVerticalPositionPage
 

    .LockAspectRatio = False

    .Top = CentimetersToPoints(0.8)

    .Left = CentimetersToPoints(10)

    .Width = CentimetersToPoints(10)

    .Height = CentimetersToPoints(2.3)

    

    

    .Line.ForeColor.RGB = RGB(255, 255, 255)

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

    

    

    .TextFrame.TextRange.Font.Name = "Arial"

    .TextFrame.TextRange.Font.Bold = True

    .TextFrame.TextRange.Font.Size = 11
 

    

    .TextFrame.TextRange.Text = strText

    

    .Visible = msoTrue

        

    End With

    

    

    Application.PrintOut

    

End If
 
 
 
 

 Do

  Loop While (ActiveDocument.Undo = True) _

       And ActiveDocument.Bookmarks.Exists("_InMacro_")
 
 
 

If bolGesperrt Then

    If ActiveDocument.ProtectionType = wdNoProtection Then

           

            ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

    End If

End If
 
 

End Sub
 

Sub DateiDruckenStandard()

  Wasserzeichen True

End Sub
 

Sub DateiDrucken()

 Wasserzeichen False

End Sub
 
 
 
 
 
 
 
 

Sub Wasserzeichen(bolStandard As Boolean)
 

Dim bolGesperrt As Boolean

bolGesperrt = False
 

  If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then

        ActiveDocument.Unprotect

        bolGesperrt = True

   End If
 
 

ActiveDocument.Bookmarks.Add "_InMacro_"
 

Selection.HomeKey Unit:=wdStory
 
 

If bolStandard Then

    Application.PrintOut

Else

    With Dialogs(wdDialogFilePrint)

    .Show

    End With

End If
 

'Start hier

If ActiveDocument.CustomDocumentProperties("VM_OriginalBrief") = "False" Then

    

    Dim strVermittlerNamenAdresse As String

    strVermittlerNamenAdresse = "Adressee of letter copy"

    

    

    Dim objShape2 As Word.Shape

    Set objShape2 = ActiveDocument.Shapes.AddTextbox( _

    Orientation:=msoTextOrientationHorizontal, _

    Left:=10, _

    Top:=10, _

    Width:=10, _

    Height:=10, _

    Anchor:=Selection.Paragraphs(1).Range)
 

    With objShape2

    .LockAnchor = True
 

    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage

    .RelativeVerticalPosition = wdRelativeVerticalPositionPage
 

    .LockAspectRatio = False

    .Top = CentimetersToPoints(5)

    .Left = CentimetersToPoints(2)

    .Width = CentimetersToPoints(12)

    .Height = CentimetersToPoints(3.5)

    

    

    .Line.ForeColor.RGB = RGB(255, 255, 255)

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

    

    

    .TextFrame.TextRange.Font.Name = "Arial"

    .TextFrame.TextRange.Font.Size = 12
 

    

    .TextFrame.TextRange.Text = strVermittlerNamenAdresse

    

    End With

    

    'does not concern the problem

    Dim strText As String

    Dim strEmpfaengerNamenOriginal As String

    

    If ActiveDocument.CustomDocumentProperties("Schreiben_an") = "AN" Then

        strEmpfaengerNamenOriginal = ActiveDocument.CustomDocumentProperties("Ausfertigung_KopieName")

        strText = "Diese Ausfertigung für die versicherte Person" + vbCrLf + "wurde gesendet an: " + strEmpfaengerNamenOriginal '+ "."

    ElseIf ActiveDocument.CustomDocumentProperties("Schreiben_an") = "Hinterbliebene" Then

        strEmpfaengerNamenOriginal = ActiveDocument.CustomDocumentProperties("Ausfertigung_KopieName")

        strText = "Diese Ausfertigung für die hinterbliebene Person" + vbCrLf + "wurde gesendet an: " + strEmpfaengerNamenOriginal '+ "."

    Else

        strEmpfaengerNamenOriginal = ActiveDocument.CustomDocumentProperties("Original_KopieName")

        strText = "Das Original wurde gesendet an:" + vbCrLf + strEmpfaengerNamenOriginal '+ "."

    End If

    

    

    Dim objShape3 As Word.Shape

    Set objShape3 = ActiveDocument.Shapes.AddTextbox( _

    Orientation:=msoTextOrientationHorizontal, _

    Left:=10, _

    Top:=10, _

    Width:=10, _

    Height:=10, _

    Anchor:=Selection.Paragraphs(1).Range)
 

    With objShape3

    .LockAnchor = True
 

    .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage

    .RelativeVerticalPosition = wdRelativeVerticalPositionPage
 

    .LockAspectRatio = False

    .Top = CentimetersToPoints(0.8)

    .Left = CentimetersToPoints(10)

    .Width = CentimetersToPoints(10)

    .Height = CentimetersToPoints(2.3)

    

    

    .Line.ForeColor.RGB = RGB(255, 255, 255)

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

    

    

    .TextFrame.TextRange.Font.Name = "Arial"

    .TextFrame.TextRange.Font.Bold = True

    .TextFrame.TextRange.Font.Size = 11
 

    

    .TextFrame.TextRange.Text = strText

    

    .Visible = msoTrue

        

    End With

    

    

    Application.PrintOut

    

End If
 
 
 
 

 Do

  Loop While (ActiveDocument.Undo = True) _

       And ActiveDocument.Bookmarks.Exists("_InMacro_")
 
 
 

If bolGesperrt Then

    If ActiveDocument.ProtectionType = wdNoProtection Then

           

            ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True

    End If

End If
 
 

End Sub
 

Sub DateiDruckenStandard()

  Wasserzeichen True

End Sub
 

Sub DateiDrucken()

 Wasserzeichen False

End Sub

Open in new window

example.doc
0
Comment
Question by:inversojvo
  • 5
  • 2
7 Comments
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 24823765
Rather than "covering" the address, why don't you just programatically mark the text as Hidden?  Format, Font, Hidden.
0
 

Author Comment

by:inversojvo
ID: 24837804
Hi,

What do you mean exactly?

I have a problem. This letter will be generated through access. Access uses other patterns with variables for putting the addressee of the original letter to the right position on the letter. (A developper of another company implemented this. I do not have any possibilities to change this code and to influence the position of the text for the addressee of the original letter.

Do I have the possibility for the text field (objShape2 in code) for the address of the letter copy to chose the option "in front of the text" (see attached file) e.g. by changing the code 93 and 94 with something like: .wdTaskPaneRevealFormatting.Visible = True
or with something like
ObjShape2.TextFrame = wd....?

Can I find on the web some information (code) to influence the properties of a text field?

Many thanks and have a nice day!
isaf
Code.doc
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 24842636
Is it currently set to "Inline with text"?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 24842665
This should take the first inline shape in your document and set it to in front of text..
Sub SetInFront()

Dim ObjShape2 As Shape
 

Set ObjShape2 = ActiveDocument.InlineShapes(1).ConvertToShape

End Sub

Open in new window

0
 

Author Comment

by:inversojvo
ID: 24857612
Hi JOrzech,

Many thanks for your help!

May I ask you what this code means? What should it change?

I would add the following code at the line 43
   
    .WrapFormat.AllowOverlap = True
    .WrapFormat.Side = wdWrapBoth

Would it change anything when I set   .LockAnchor = True to   .LockAnchor = false?

Sorry but I do not know so much about vba for word.

Many thanks and have a nice day!
isaf
0
 
LVL 37

Accepted Solution

by:
Joanne M. Orzech earned 500 total points
ID: 24862834
There is only one line of code there that does anything...which is:
Set ObjShape2 = ActiveDocument.InlineShapes(1).ConvertToShape

It simply takes the first inline shape in your document and converts it to be in front of text.

Before adding or changing anything... at least try to just run the code I posted and make sure it works the way you want it to.  Then you can fine tune it isaf.
0
 
LVL 37

Expert Comment

by:Joanne M. Orzech
ID: 24960122
Thank you.  I'm glad I could help....

Joanne Orzech
MS Word MVP
EE Zone Advisor
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

707 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

13 Experts available now in Live!

Get 1:1 Help Now