Solved

Word setting by using macros for printing copy

Posted on 2009-07-10
7
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
This video walks the viewer through the process of creating Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…

749 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