Align only last-inserted paragraph in footer
Author |
Message |
Grace #1 / 14
|
 Align only last-inserted paragraph in footer
I inherited somebody else's template and there are things that don't work right for our users. In the footer, the path\filename is inserted after anything else thre, but after the filename field is inserted and I want to right-align just this one line, the whole footer is right-aligned instead. Can I make it to right-align just a filename field? The code is below. Also, the path is inserted as a drive letter. What I really need is a UNC path. How can I get that? I appreciate any help, I am a VBA newbie. DocName = LCase(MyDoc.FullName) With MyDoc.Sections(1).Footers(wdHeaderFooterPrimary) strFooter = LCase(.Range.Text) Select Case strFooter Case Is = vbCr 'Footer contains nothing MyDoc.Fields.Add .Range, wdFieldFileName, "\* Lower\p \*MergeFormat" .Range.ParagraphFormat.Alignment = wdAlignParagraphRight Case Is = DocName & vbCr 'Footer contains only DocName .Range.Text = "" MyDoc.Fields.Add .Range, wdFieldFileName, "\* Lower\p \*MergeFormat" .Range.ParagraphFormat.Alignment = wdAlignParagraphRight Case Else 'Footer contains other stuff iPos = InStr(1, strFooter, DocName, vbTextCompare) If iPos = 0 Then 'Something in footer with no DocName strFooter = .Range.Text .Range.Collapse wdCollapseEnd retVal = .Range.Fields.Add(.Range, wdFieldFileName, "\* Lower\p \*MergeFormat", True) .Range.Paragraphs.Last.Alignment = wdAlignParagraphRight .Range.InsertBefore strFooter End If End Select End With Thanks, Grace
|
Mon, 10 Feb 2003 03:00:00 GMT |
|
 |
Tony Strazzer #2 / 14
|
 Align only last-inserted paragraph in footer
Hi Grace, I haven't looked at your code (not enough time) but here are some immediate comments that may help. Alignment can only be applied to paragraphs. If you filename is on a paragraph of its own then the simplest way to right align it is Selection.ParagraphFormat.Alignment = wdAlignParagraphRight when the cursor is on the paragraph. otherwise you could defile a style to do this and apply that style to the filename. Make sure that the fielname is on a paragraph of its own. If the whole thing right aligned then it isn't and you need to insert a paragraph first. If the filename is on a paragraph with other text then you need to insert a right aligned tab at the RHS of the paragraph and insert a tab char (use vbTab constant or chr$(9) ) before you insert the filename. Again you can set the tab in a style. Word97 by default inserts the filename as UNC unless you have the registry setting "DontUseUNC" set to 1. This setting only applies to versions after Service pack 1. Check the registry and change the setting to 0 if it is 1. See this ref for details http://support.microsoft.com/support/kb/articles/Q178/4/05.ASP Hope this helps Regards TonyS. --- Please post any follow-up or new questions to the Newsgroups so that others may benefit therefrom or contribute thereto. Sent via Deja.com http://www.deja.com/ Before you buy.
|
Tue, 11 Feb 2003 08:41:20 GMT |
|
 |
Grace #3 / 14
|
 Align only last-inserted paragraph in footer
Tony, thank you for your comments. I have a file name field on a separate paragraph, but still everything gets right-aligned when I use .Range.ParagraphFormat.Alignment = wdAlignParagraphRight I don't see selection.ParagraphFormat available in the footer. I am using .Range. There might be something else in the code that makes it behave this way and I don't understand it. About UNC path, I am using Word 2000 and I checked the registry - I don't have an entry for DontUseUNC so according to the article, it should resolve the path to UNC. Well, it does not. I am kind of desperate, I need the template included in the Zen application package for Office, and I am struggling... Thanks for your help, Grace
|
Tue, 11 Feb 2003 09:25:53 GMT |
|
 |
Jon Pawle #4 / 14
|
 Align only last-inserted paragraph in footer
Hello Grace, The code you posted has the following construct With MyDoc.Sections(1).Footers(wdHeaderFooterPrimary) '... more code here End With When you then refer to the .Range within the With...End what VBA "really" uses is MyDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range So, when you use the command .Range.ParagraphFormat.Alignment = wdAlignParagraphRight VBA really runs MyDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.ParagraphFormat.Align ment = wdAlignParagraphRight. The range of the wdHeaderFooterPrimary includes *all* the text in the footer. That is why the result of this command is to right align the whole footer. I think you need to only set the alignment of the paragraph that you have jut inserted. Does the following work? .Range.Select '(this is really MyDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Select) Selection.ParagraphFormat.Alignment = wdAlignParagraphRight Cheers, Jon Quote:
>Tony, thank you for your comments. I have a file name field on a separate >paragraph, but still everything gets right-aligned when I use > .Range.ParagraphFormat.Alignment = wdAlignParagraphRight >I don't see selection.ParagraphFormat available in the footer. I am using >.Range. There might be something else in the code that makes it behave this >way and I don't understand it. >About UNC path, I am using Word 2000 and I checked the registry - I don't >have an entry for DontUseUNC so according to the article, it should resolve >the path to UNC. Well, it does not. >I am kind of desperate, I need the template included in the Zen application >package for Office, and I am struggling... >Thanks for your help, >Grace
|
Tue, 11 Feb 2003 10:30:46 GMT |
|
 |
Grace #5 / 14
|
 Align only last-inserted paragraph in footer
Thanks, Jon, but your suggestion is not working... I will probably end up putting a bookmark there and just "go to it". Still UNC path unresolved, too <sigh>. Grace
|
Tue, 11 Feb 2003 14:13:52 GMT |
|
 |
Tony Strazzer #6 / 14
|
 Align only last-inserted paragraph in footer
Jon Pawley has looked at your code, his response looks like it should do the trick for the alignment. Unfortunately I don't have Word2000 so I can't check the UNC issue. The file you are testing on is on a network drive isn't it? If all else fails you can use the code from this article to convert the drive letter to a UNC spec. Article Q192689 - HOWTO: Get UNC Path From a Mapped Network Share's Drive Letter http://mspss.directhit.com/fcgi-bin/RedirURL.fcg?url=http% 3A//support.microsoft.com/support/kb/articles/Q192/6/89.ASP%3FLN%3DEN- US%26SD%3Dgn%26FR%3D0&qry=Q192689&rnk=1&src=DHCS_MSPSS_gn_SRCH&SPR=MSALL TonyS. --- Please post any follow-up or new questions to the Newsgroups so that others may benefit therefrom or contribute thereto. Sent via Deja.com http://www.deja.com/ Before you buy.
|
Tue, 11 Feb 2003 14:28:13 GMT |
|
 |
Tony Strazzer #7 / 14
|
 Align only last-inserted paragraph in footer
Quote: > Jon Pawley has looked at your code, his response looks like it should > do the trick for the alignment. > Unfortunately I don't have Word2000 so I can't check the UNC issue. > The file you are testing on is on a network drive isn't it? > If all else fails you can use the code from this article to convert the > drive letter to a UNC spec. > Article Q192689 - HOWTO: Get UNC Path From a Mapped Network Share's > Drive Letter
OOps! this is the correct reference for this http://support.microsoft.com/support/kb/articles/Q192/6/89.ASP Quote: > TonyS. > --- > Please post any follow-up or new questions to the Newsgroups > so that others may benefit therefrom or contribute thereto. > Sent via Deja.com http://www.deja.com/ > Before you buy.
-- TonyS. --- Please post any follow-up or new questions to the Newsgroups so that others may benefit therefrom or contribute thereto. Sent via Deja.com http://www.deja.com/ Before you buy.
|
Tue, 11 Feb 2003 03:00:00 GMT |
|
 |
Tony Strazzer #8 / 14
|
 Align only last-inserted paragraph in footer
Grace, Having looked at your code (and created a sample) the solution is easy. Swap the order of the insert and paragraph align lines of code in the Case Else part of the code. ie this line 'retVal = .Range.Fields.Add(.Range, wdFieldFileName, "\* Lower\p \*MergeFormat", True) replaces the range (original footer) with the filename field 'this inserts the original footer before the paragraph 'with the field that you just inserted. .Range.InsertBefore strFooter 'this formats the last paragraph of the range .Range.Paragraphs.Last.Alignment = wdAlignParagraphRight The problem when the code is the other way around is caused by virtue of the fact that having inserted the field paragraph and formatted it to right align, when you do the .Range.InsertBefore strFooter to insert the original footer text it picks up the alignment from the paragraph it is on. Cheers TonyS. --- Please post any follow-up or new questions to the Newsgroups so that others may benefit therefrom or contribute thereto. Sent via Deja.com http://www.deja.com/ Before you buy.
|
Tue, 11 Feb 2003 03:00:00 GMT |
|
 |
Grace #9 / 14
|
 Align only last-inserted paragraph in footer
I switched the order and now the last paragraph is aligned correctly, but everything before is changed to Left-Aligned, and it does not matter that I have several separate lines (paragraphs) there. Thanks for all your help, but it looks like it's not going to work... My code: Case Else 'Footer contains other stuff iPos = InStr(1, strFooter, DocName, vbTextCompare) If iPos = 0 Then 'Something in footer with no DocName strFooter = .Range.Text .Range.Collapse wdCollapseEnd retVal = .Range.Fields.Add(.Range, wdFieldFileName, "\* Lower\p \*MergeFormat", True) .Range.InsertBefore strFooter .Range.Paragraphs.Last.Alignment = wdAlignParagraphRight End If Thanks again, Grace
|
Tue, 11 Feb 2003 03:00:00 GMT |
|
 |
Tony Strazzer #10 / 14
|
 Align only last-inserted paragraph in footer
Hi Grace, Don't give up so easily. I tested with existing paras already left aligned. The problem seems to be the way that the existing text is replaced by the insertfield instruction. That means that when it self is restored it will pick up the default formatting style of the paragraph. If the existing text was formatted using the same style but with additional explicit formatting such as centering then it will lose some of that formatting. Sorry I can't test further now (its 6:30am on a satruday here and I am off to a dog show in 15min) but I suggest you change the code so that it doesn't insert the field code over the top of the existing text. Try stepping throught the code whilst looking at the document to work out where and when to change the code. You can use the undo command (keyboard) in word to undo the last action and the retry or try another line of code (Ctrl+F9) until it works. Try working with the selection object. it will be easier. to do this put in .range.select before the collapse line and thereafter use selection.range. You will of course then need to jump out of the header/footer area and back to the maindocument. I will look at this tonight when I get back. Cheers
Quote: > I switched the order and now the last paragraph is aligned correctly, but > everything before is changed to Left-Aligned, and it does not matter that I > have several separate lines (paragraphs) there. Thanks for all your help, > but it looks like it's not going to work... > My code: > Case Else 'Footer contains other stuff > iPos = InStr(1, strFooter, DocName, vbTextCompare) > If iPos = 0 Then > 'Something in footer with no DocName > strFooter = .Range.Text > .Range.Collapse wdCollapseEnd > retVal = .Range.Fields.Add(.Range,
wdFieldFileName, "\* Quote: > Lower\p \*MergeFormat", True) > .Range.InsertBefore strFooter > .Range.Paragraphs.Last.Alignment =
wdAlignParagraphRight Quote: > End If > Thanks again, > Grace
-- TonyS. --- Please post any follow-up or new questions to the Newsgroups so that others may benefit therefrom or contribute thereto. Sent via Deja.com http://www.deja.com/ Before you buy.
|
Tue, 11 Feb 2003 03:00:00 GMT |
|
 |
Grace #11 / 14
|
 Align only last-inserted paragraph in footer
Tony, you are the greatest - you have great patience... I got it working with Selection (I still have to get out of the footer, but it's no big deal). Case Else 'Footer contains other stuff .Range.Fields.Update iPos = InStr(1, strFooter, DocName, vbTextCompare) If iPos = 0 Then .Range.Fields.Update 'Something in footer with no DocName strFooter = .Range.Text .Range.Select Selection.Cut retVal = .Range.Fields.Add(.Range, wdFieldFileName, "\* Lower\p \*MergeFormat", True) Selection.Paste .Range.Paragraphs.Last.Alignment = wdAlignParagraphRight End If Thanks for all your suggestions. Now if you could only tell me how to make the SaveAs window open in FileSaveAs module...<g> MyDoc.SaveAs does not do anything. The only option I see is pass it a file name and I can't have it. Will wdDialogFileSaveAs work? All this is still part of the whole template - it has to update the field (or remove it if required) on SaveAs. How was the dog show? Where there any ponies, too? <grin> I hope you have a very nice weekend. Grace
|
Tue, 11 Feb 2003 03:00:00 GMT |
|
 |
Grace #12 / 14
|
 Align only last-inserted paragraph in footer
Tony, it looks like Jonathan West answered a question similar to mine about SaveAs today, so please disregard my last request. Thanks again for all your help, Grace
|
Wed, 12 Feb 2003 11:09:51 GMT |
|
 |
Tony Strazzer #13 / 14
|
 Align only last-inserted paragraph in footer
Hi Grace, I am glad you got it working by yourself. I had a look at it again before logging on and have code for you that works without using the selection method. I will post it at the end. We had a great at the dog show. Sorry no Ponies. We have two (beautiful) Italian Greyhounds. Rani a 2 1/2 yo male and his daughter Skeeta 5mth old. Rani won Best of Breed. The best part was that we were able to visit Skeeta's Mum (she was only 1.5 hours out of our way after 2hr travelling to get to the dog show <<G>>.) Now for the serious stuff. The following code will deal with the problem *********start of code section 'Add this declaration at the top of the code Dim myRange As Range 'Replace the Case Else code with this. Case Else 'Footer contains other stuff iPos = InStr(1, strFooter, DocName, vbTextCompare) If iPos = 0 Then 'Something in footer with no DocName strFooter = .Range.Text 'define our own range to work with Set myRange = .Range 'set the start and end of this range both to the end myRange.Start = myRange.End 'insert the field relative to our range retVal = .Range.Fields.Add(myRange, wdFieldFileName, "\* Lower\p \*MergeFormat", True) 'move the field to its own paragraph myRange.InsertBefore vbCr 'right align the last para of the range .Range.Paragraphs.Last.Alignment = wdAlignParagraphRight End If End Select *********end of code section Quote: >Now if you could only tell me how to make > the SaveAs window open in FileSaveAs module...<g> MyDoc.SaveAs does
not do If I understand you correctly you want to launch the filesaveas dialog. You can do this with the following. Dim Ans Dim dlg As Dialog Set dlg = Dialogs(wdDialogFileSaveAs) 'Display the dialog and return a value 'for the button pressed but don't do the actual save Ans = dlg.Display If Ans = -1 Then 'Save button was pressed 'put any additional code here. 'eg check the file name that was selected 'eg fn = dlg.Name 'do the actual save dlg.Execute End If Hope this is what you want. Cheers TonyS. --- Please post any follow-up or new questions to the Newsgroups so that others may benefit therefrom or contribute thereto. Sent via Deja.com http://www.deja.com/ Before you buy.
|
Wed, 12 Feb 2003 03:00:00 GMT |
|
 |
Grace #14 / 14
|
 Align only last-inserted paragraph in footer
Tony, you have my eternal grattitude. Now I should have the darn template ready by Monday. As you noticed, VB is not my strong point, I am a FoxPro girl <g>. Congratulations on Rani's Best of Breed award. I love dogs, though I don't have any now. I used to have them when I lived in my old country. Thanks again, now back to my labors.... Grace
|
Wed, 12 Feb 2003 03:00:00 GMT |
|
|
|