Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to code carriage return in a macro 4

Status
Not open for further replies.

sinbad99

Technical User
Feb 16, 2012
34
GB
In a Word macro for a header and footer, I want to have two lines on the header. I need in some way to declare char(10).

This is what I have, but the second line - the fullpoints as a dotted rule - doesn't appear.
Code:
 Sub HeaderFooterObjectBest_English()
  Dim MyText As String
    MyHeaderText = "..........................."
  MyHeaderText = "Paul | new words for the week | Best-English.org | 1 of 1"
  MyFooterText = "Best-English dot org"
  Selection.Font.Name = "Courier New"
      Selection.Font.Size = 9
      With ActiveDocument.Sections(1)
    .Headers(wdHeaderFooterPrimary).Range.Text = MyHeaderText
    .Footers(wdHeaderFooterPrimary).Range.Text = MyFooterText
  End With
End Sub

Be very grateful for some advice.
 
RE: macropod's post. Totally agree. If the issue is format (spacing) then proper use of style is the ONLY way to go.

Besides, you should be using styles anyway.

 
ONLY way to go
sorry but i have to jump in here. Seriously the 'only way', how many times can you honestly say there is only one way of doing something in the office suite with vba. That's what makes this suite so powerful its ability to accomplish a task in several ways playing on the strengths of the developer. Also re strongm combining several lines of code or built in functions to either enhance or lessen the lines of code required is and will always be a good idea. Granted the first line isn't necessary and it could be accomplished with one line of code. Regardless it gives the op the idea that there are options available ... Choices ... Not just one way of accomplish a task in Office

HTH << MaZeWorX >> "I have not failed I have only found ten thousand ways that don't work" <<Edison>>
 
>its ability to accomplish a task in several ways playing on the strengths of the developer

I'm sure that you must have seen more badly written or unneccessary Office VBA code than I have that adheres to this idea, rather than to the idea that the developer could, alternatively, play to the strengths of the software.

It wasn't all that long ago that I was asked to help someone out with some VBA that was supposed to identify section headings on some imported plaintext by finding single words alone on a line (and then discovering, amongst other issues, that not all such headings were only one word), and then making them bold and increasing the font size for each one it found. Do you think that was a good choice? Given that this was essentially a poorly thought out version of Range.AutoFormat

Having a choice is all very well. Making the right choice can be vital, and save a lot of time and pain now and in the future. And I'd hope that here in tek-tips we'd try and point people towards the good choices. And yes there will always be some argument and discussion over what the good choices are - and that's a good thing in itself.

And on that basis, I'd argue that the example we are talking about offers no more than your own example in this thread (showing how to concatenate strings with a new line), whilst at the same time introducing a poor programming practice (elimination of a meaningful variable name). To me, that means it is not a good example.
 
If by meaningful variable name you mean a style name, then for sure. By stating only, I meant that if you want to identify and action paragraphs (be it spacing, font, font size or any other attribute) - and make no mistake these "lines" ARE paragraphs - then I stand by my statement. The only way to go is to use styles.

Word is designed around styles. Period. It is the core of Word.

To state that because there are multiple ways of doing something in Word makes those ways equivilent is absurd. For example to state that using Selection (rather than Range) to do things makes using Selection equivalent to using Range is nonsense.

Note that, sure, making general comments about Office, is one thing, but we are talking about specifically Word. And in Word using styles is by far the better way of dealing with things like paragraph attributes. And even MORE so if you are using VBA.

 
Actually, one thing that makes using styles properly superior is that is that if styles were used properly...in this case there would be no need for VBA at all.

 
Just in case you thought otherwise, my comment was not aimed at you, Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top