Solved

Word setting by using macros for printing copy

Posted on 2009-07-10
7
284 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Introduction Authors who set out to write any sort of lengthy piece for online submission—be it a long question or comment on a technical form, an article, or a substantial blog entry—often find it useful to work up a draft in an editor other t…
Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This video walks the viewer through the process of creating a watermark for their document, customizing it, and saving it for viewing/printing needs.
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.

813 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

14 Experts available now in Live!

Get 1:1 Help Now