Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-30-2017, 04:32 AM
dxdevil dxdevil is offline Textboxes position isn't equal to initial position Windows 7 64bit Textboxes position isn't equal to initial position Office 2013
Novice
Textboxes position isn't equal to initial position
 
Join Date: Jan 2017
Posts: 1
dxdevil is on a distinguished road
Unhappy 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 only Thing i do is this:
Code:
 'get coordinates for textbox' position
            coordinates() = giveRightPosition(0)
            
            'create shape
            Dim shp As Word.Shape
            'Werte unten mittig (321,561,200,25) bei einer SGröße von 11
            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
Code:
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

Last edited by dxdevil; 01-30-2017 at 04:35 AM. Reason: Failed Code
Reply With Quote
Reply

Tags
header, textbox, vba code



Similar Threads
Thread Thread Starter Forum Replies Last Post
Different page number position Yankel Word 2 08-01-2014 04:48 AM
Shadow Position shanemarkley Excel 0 07-30-2014 08:23 PM
DL envelope window position rogerwilding Word 1 02-20-2013 01:57 PM
Textboxes position isn't equal to initial position VBA: how can I know the position on a document? tinfanide Excel Programming 3 02-27-2012 03:24 PM
fix position for a segment in a doc tai Word 3 10-20-2011 01:04 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:22 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft