Results 1 to 3 of 3

Thread: Early?late Binding?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Jul 2005
    Posts
    74
    Location

    Early?late Binding?

    From Excel, I prepare a small Word memo
    [VBA]
    Public Sub Memo()
    Dim a As Integer, b As Integer, c As Integer, d As Integer
    Dim WordApp As Object
    Dim myrange1 As Object, myrange2 As Object
    Dim wordDoc As Object
    Set WordApp = CreateObject("Word.Application")

    SaveAsName = ThisWorkbook.Path & "\" & "wren" _
    & Format(Date, "mmddyyyy") & ".doc"

    With WordApp
    .documents.Add
    Set wordDoc = WordApp.activedocument
    With .Selection
    .Font.Size = 14
    .Font.Bold = True
    .paragraphformat.Alignment = 1
    .typetext Text:="MY REPORT"
    .typeparagraph
    .typeparagraph
    .Font.Size = 12
    .paragraphformat.Alignment = 0
    .Font.Bold = False
    .typetext Text:="Date:" & vbTab & _
    Format(Date, "mmmm d, yyyy")
    [/VBA]

    Obviosly not the whole routine, but as Word is set as an object, this would be an example of late binding.

    so when i use

    [VBA]
    Public Sub Memo()
    Dim a As Integer, b As Integer, c As Integer, d As Integer
    Dim WordApp As Word.Application
    Dim myrange1 As Object, myrange2 As Object
    Dim wordDoc As Word.Document
    Set WordApp = New Word.Application
    SaveAsName = ThisWorkbook.Path & "\" & "wren" _
    & Format(Date, "mmddyyyy") & ".doc"

    With WordApp
    .documents.Add
    Set wordDoc = WordApp.activedocument
    With .Selection
    .Font.Size = 14
    .Font.Bold = True
    .paragraphformat.Alignment = 1
    .typetext Text:="MY REPORT"
    .typeparagraph
    .typeparagraph
    .Font.Size = 12
    .paragraphformat.Alignment = 0
    .Font.Bold = False
    .typetext Text:="Date:" & vbTab & _
    Format(Date, "mmmm d, yyyy")
    [/VBA]

    I would have expected this example of "very early" binding to execute significantly quicker, but I was disappointed. Any ideas as to why. Is my binding strategy flawed in some way? I have set the reference to Word.
    Last edited by clvestin; 12-21-2005 at 07:35 AM. Reason: Add'l info

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •