Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

applying different font styles

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
tborthwick@gmail.com - 26 Mar 2008 22:49 GMT
Hello,

I have a script that reads several items in a loop and creates a
header then a table for each. The header and the table text should
have different styles, but all the text gets the style I first set for
the header. In the script below you can see I try to set the font size
to 10 before adding a table, but the size stays at 12, which is set
earlier. Is it because I'm using the same range? I tried using two
range variable, one for the header and one for the table, but it
didn't change anything. Any help would be appreciated.

Thanks,

Tom

Dim attr As AttributeObj
Dim myRange As Object

Sub Main

    Dim Word As Object
    Dim Docs As Object
    Dim WordBasic As Object
    Dim ActiveDoc As Object

    Dim diag As Diagram
    Dim mdl As Model
    Dim sm As SubModel
    Dim so As SelectedObject
    Dim id As Integer
    Dim ent As Entity
    Dim attr As AttributeObj

    Set Word = CreateObject("Word.Application")
    Word.Visible = True
    Word.Options.CheckGrammarAsYouType = False
    Word.Options.CheckSpellingAsYouType = False

    Set ActiveDoc = Word.Documents.Add()

    Set diag = DiagramManager.ActiveDiagram
    Set mdl = diag.ActiveModel
    Set sm = mdl.ActiveSubModel

   For Each so In sm.SelectedObjects
        If so.Type = 1 Then
            id = so.ID
            Set ent = mdl.Entities.Item(id)

                       'Write out header
            Set myRange = ActiveDoc.Range
            myRange.Font.Size = 12
            myRange.Collapse 0
                  myRange.InsertAfter ent.EntityName & vbCrLf

            If ent.Note <> "" Then
                Set myRange = ActiveDoc.Range
                myRange.Collapse 0
                      myRange.Font.Size = 10

                myRange.InsertAfter ent.Note & vbCrLf
                 End If

                 Set myRange = ActiveDoc.Range
                 myRange.Font.Size = 10
                 myRange.Collapse 0
                 Set objTable = myRange.Tables.Add(Range:=myRange,
NumRows:=ent.Attributes.Count, NumColumns:=3)

            Dim curRow As Integer
            curRow = 1

            'Add column headings
            objTable.Cell(curRow, 1).Range.Text = "Column name"
            objTable.Cell(curRow, 2).Range.Text = "Datatype"
            objTable.Cell(curRow, 3).Range.Text = "Notes"
            curRow = curRow + 1

            For Each attr In ent.Attributes
                objTable.Cell(curRow, 1).Range.Text = attr.ColumnName
                objTable.Cell(curRow, 2).Range.Text = Datatype(attr.Datatype,
attr.DataLength)
                objTable.Cell(curRow, 3).Range.Text = attr.Notes

                curRow = curRow + 1
            Next

            '4, 27, 36
            objTable.autoFormat(36)
            objTable.Columns(1).Width = 135
            objTable.Columns(2).Width = 80
            objTable.Columns(3).Width = 235

            Set myRange = ActiveDoc.Range
            myRange.Collapse 0
           myRange.InsertAfter  vbCrLf

        End If
   Next
End Sub
Jean-Guy Marcil - 28 Mar 2008 19:56 GMT
> Hello,
>
[quoted text clipped - 96 lines]
>     Next
> End Sub

I do not have time to study you code in details right now, but if you will
allow me, let me make one observation and one recommendation which might help
you solve your problem on your own.

Observation:

I see that you are using the range object, which is excellent.
But, you use:
  'Write out header
     Set myRange = ActiveDoc.Range
     myRange.Font.Size = 12
     (...)

and a few lines lower, you use:
     Set myRange = ActiveDoc.Range
     myRange.Font.Size = 10

You are effectively setting the whole document to a font size of 12, and
then the whole document again to a font of 10...

Recommendation:
Sprinkle a few
  myRange.Select statement
in your code; and/or use the local window in the VBA editor.
Then, debug your code step by step with F8 key and see how your Range object
changes. You have to code so that the Range object points only to part you
want before executing any properties or methods.
Also, read the VBA help on the Range object and some of its associated
properties/methods such as ".InsertAfter."

Good luck!
InAnyPlace - 28 Mar 2008 20:19 GMT
Access my profile Details in:

                 http://al-bernardes.sites.uol.com.br/
                 http://www.linkedin.com/in/andrebernardes
                 http://andrebernardes.myplaxo.com/

André Luiz Bernardes

On 28 mar, 15:56, Jean-Guy Marcil
<JeanGuyMar...@discussions.microsoft.com> wrote:
> "tborthw...@gmail.com" wrote:
> > Hello,
[quoted text clipped - 129 lines]
>
> Good luck!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.