×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Open Existing Word Document From Excel?

Open Existing Word Document From Excel?

Open Existing Word Document From Excel?

(OP)
I would like to open an existing word document using a command button click.  I am new to VBA and have been guessing my way around to this point, this is a bit tougher for me.  I am wanting to open the word document and merge data from excel, so a fully automated open and merge sequence would be great if possible.

RE: Open Existing Word Document From Excel?

This was a very specific application of opening a Word document from a Lowtran atmospheric transmission model, finding a specific phrase in the output, copying the data value and pasting it into an Excel sheet.  The analysis program is iterated over 25 distance values, so there's a 25 iteration copy loop.  It's pretty kludgy; I wrote it 4 yrs ago and I'm not even sure I can remember why everything is the way it is.  It was mostly macro recorded and glued together with some heavy-duty research.

Good Luck

TTFN

Sub LT7()
'
' Lowtran7 macro to paste Lowtran transmission results into Excel Spreadsheet
' Macro recorded 1/23/98 by mei
'

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    Dim ColIndex, RowIndex, StartRow, Done
    Dim FileName, SheetName
    
    Dim WordApp As Object
    Dim Trans As String
       
    Set WordApp = GetObject(, "word.application")
    
    FileName = ActiveWorkbook.Name
    SheetName = ActiveSheet.Name
    
    Sheets(SheetName).Select
    Done = False
    ColIndex = ActiveCell.Column
    RowIndex = ActiveCell.Row
    StartRow = RowIndex
    
    Cells(RowIndex, ColIndex).Select
    With WordApp.Selection.Find
        .Text = "transmittance ="
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    For Index = 1 To 25
        WordApp.Selection.Find.ClearFormatting
        WordApp.Selection.Find.Execute
        WordApp.Selection.MoveRight unit:=wdCharacter, Count:=1
        WordApp.Selection.MoveRight unit:=wdSentence, Count:=1, Extend:=wdExtend
'        WordApp.Selection.Copy
        Trans = WordApp.Selection.Text
        WordApp.Selection.MoveDown unit:=wdLine
        
        Cells(RowIndex, ColIndex).Select
'        ActiveSheet.Paste
        ActiveCell.Formula = Trans
        
        RowIndex = RowIndex + 1
    Next
    Cells(StartRow, ColIndex).Select
End Sub

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources