Thema Datum  Von Nutzer Rating
Antwort
Rot Textboxes position isn't equal to initial position
30.01.2017 12:53:15 dxdevil
*****
NotSolved

Ansicht des Beitrags:
Von:
dxdevil
Datum:
30.01.2017 12:53:15
Views:
893
Rating: Antwort:
  Ja
Thema:
Textboxes position isn't equal to initial position
Hey Guys, I'm new to VBA and programming a small macro. Its Task is to put a small TextBox on every page at the top and bottom at the exact same Position. It works fine on 'normal' documents, but on specific the textboxes move their Position by only a few mm. I think this is caused by the documents Header and layout. The values of giveRightPos() aren't changing, but the textboxes' pos differs. The only Thing i do is this: 'get coordinates for textbox' position coordinates() = giveRightPosition(0) 'create shape Dim shp As Word.Shape Set shp = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, _ coordinates(0), coordinates(1), 200, 35) With shp .Name = "TB_" & CStr(Rnd()) .Line.Visible = msoFalse .RelativeHorizontalPosition = wdRelativeHorizontalPositionPage .RelativeVerticalPosition = wdRelativeVerticalPositionPage With .TextFrame.TextRange .text = ButtonText .ParagraphFormat.Alignment = wdAlignParagraphCenter With .Font .Name = "Arial" .Size = 11 End With End With End With ______ Public Function giveRightPosition(position As Integer) As Integer() ' position defines the textbox position: ' 0 = top ' 1 = bottom Set myDoc = ActiveDocument Dim orientation As WdOrientation Dim paperSize As WdPaperSize Dim paperWidth As Integer Dim paperHeight As Integer Dim Message As Integer Dim coordinates(2) As Integer orientation = myDoc.PageSetup.orientation paperSize = myDoc.PageSetup.paperSize paperWidth = myDoc.PageSetup.PageWidth paperHeight = myDoc.PageSetup.PageHeight 'Debug Only test = MsgBox(paperSize, vbYesNo, paperWidth) 'check paper format If paperSize = wdPaperA4 Then coordinates(0) = (paperWidth / 2) - (200 / 2) 'textbox.width is 200 and textalignment is center ' check selected position for calculation of vertical coordinates If position = 0 Then coordinates(1) = 30 'Debug Only Message = MsgBox("detected top!", vbOKOnly, "") Else coordinates(1) = paperHeight - 50 '30 'Debug Only Message = MsgBox("detected bottom!", vbOKOnly, "") End If Else Message = MsgBox("Your paperformat is invalid! Process aborted.", vbOKOnly, "Error") End If I hope you guys can help me, i Need to fix that issue. The macro should give a **** on everything and just place these textboxes. Thxxx

Ihre Antwort
  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen
Thema: Name: Email:



  • Bitte beschreiben Sie Ihr Problem möglichst ausführlich. (Wichtige Info z.B.: Office Version, Betriebssystem, Wo genau kommen Sie nicht weiter)
  • Bitte helfen Sie ebenfalls wenn Ihnen geholfen werden konnte und markieren Sie Ihre Anfrage als erledigt (Klick auf Häckchen)
  • Bei Crossposting, entsprechende Links auf andere Forenbeiträge beifügen / nachtragen
  • Codeschnipsel am besten über den Code-Button im Text-Editor einfügen
  • Die Angabe der Emailadresse ist freiwillig und wird nur verwendet, um Sie bei Antworten auf Ihren Beitrag zu benachrichtigen

Thema Datum  Von Nutzer Rating
Antwort
Rot Textboxes position isn't equal to initial position
30.01.2017 12:53:15 dxdevil
*****
NotSolved