![]() |
#1
|
|||
|
|||
![]()
Hi All
I wonder if someone can help with a puzzle I have. On the top of each page of my document , I have a text box which starts with the text "Main Accounts Group :". Each of these text boxes is wrongly positioned to the right of centre on each page. I need to select and move each of the text boxes containing this text across each page to the left margin so that it is line with other text below. If anyone can help with some VBA to achieve this , I'd be grateful. Best Wishes , Last edited by Chayes; 02-21-2016 at 04:41 PM. |
#2
|
||||
|
||||
![]()
If you put one such textbox into the page header and align it as required, you could simply delete the rest.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
HI
Thanks for getting back. Yes , I can see that this would work also , but as it can be a big task over many pages I was hoping to automate it via VBA. By hand it would be a large and repetitive task. Best Wishes , |
#4
|
||||
|
||||
![]()
Are there other textboxes in the document?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
Hi
Yes , there are , so it would need only to operate on those starting with the text "Main Accounts Group :". The text following this phrase can vary Presently , this is the heading to each page and each sits out-of-place on the mid-right of each page. I'm hoping to be able to move them over to the left and align with the rest of the text below. I'll attach a sample file so you can see the issue. Ideally , once the VBA is run , the word 'Main' would sit over the word 'Simple' on each page. Thanks for your help. Best Wishes , |
#6
|
||||
|
||||
![]()
It's a good thing you provided the attachment; they're not textboxes but frames. As per my previous advice, you could move one such frame into the page header and delete the rest, but the following code just changes the alignment:
Code:
Sub Demo() Application.ScreenUpdating = False Dim i As Long, sngPos As Single With ActiveDocument For i = 1 To .Frames.Count With .Frames(i) If .Range.Text Like "*(??? ## - ??? ##)" Then sngPos = .HorizontalPosition Exit For End If End With Next For i = 1 To .Frames.Count With .Frames(i) If InStr(.Range.Text, "Main Accounts Group :") > 0 Then .HorizontalPosition = sngPos End If End With Next End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
OK thanks for your help. Much appreciated.
I ran the code and it gives an error unfortunately. This being said , when I dismiss the error box it does seem to have done the job! At any rate I've attached a zip with the error messages , and hopefully this will help to track down where the issue lies. Thanks again |
#8
|
||||
|
||||
![]()
That error message makes no sense - it implies there are less frames in the document than it has just counted...
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
![]()
Yes , I see. It's certainly a strange one.
To avoid the message box denoting the error , I tried 'On Error Resume Next' at the top of the code and after a pause it does go on to do the job. I do agree though that it's hard to see why the error should occur. |
![]() |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
Samantha Jean | Word | 7 | 02-09-2017 02:22 AM |
how to add text to a document without existing text moving around? | Athalwolf | Word | 7 | 12-16-2014 05:16 PM |
![]() |
Rich18144 | Word | 3 | 05-29-2014 09:05 AM |
Text disappears (but headings and text boxes ok) when printing 1 page of a document | msfordummies | Word | 1 | 02-21-2013 10:28 PM |
Word2010 check boxes and plain text content control boxes in same table | fcsungard | Word | 5 | 06-01-2012 01:16 AM |