We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Word setting by using macros for printing copy

inversojvo
inversojvo asked
on
Medium Priority
305 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
Comment
Watch Question

Joanne M. OrzechManager, Document Services Center
Top Expert 2004

Commented:
Rather than "covering" the address, why don't you just programatically mark the text as Hidden?  Format, Font, Hidden.

Author

Commented:
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
Joanne M. OrzechManager, Document Services Center
Top Expert 2004

Commented:
Is it currently set to "Inline with text"?
Joanne M. OrzechManager, Document Services Center
Top Expert 2004

Commented:
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

Author

Commented:
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
Manager, Document Services Center
Top Expert 2004
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Joanne M. OrzechManager, Document Services Center
Top Expert 2004

Commented:
Thank you.  I'm glad I could help....

Joanne Orzech
MS Word MVP
EE Zone Advisor
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.