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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word-Excel not playing nice together :(

Status
Not open for further replies.

Pegasus0990

Technical User
Nov 16, 2006
27
0
0
US
i have not touched this code in a couple of months, but now i am on a different computer. when i use to push the 'command button' all the data i was trying to get from excel was passed to word. however now, when the 'command button' is pushed, it just accepts getting pushed, then freezes. i can tell that values are being passed to the Word VB by using 'watches.' however, nothing is outputted into the Word file, and the form doesnt dissapear. What code will make the Form and the instance of the Excel file close, because every time i run the macro, the referenced Excel Doc opens again.

i have the following referenced.

VB for apps
word 11.0 object library
excel 11.0 object library
office 11.0 object library
forms 2.0 object library
ole automation
normal

//the following code is in my Word BF//

Public Sub CommandButton1_Click()
HideListBoxes

Dim oDoc As Word.Document

Set oDoc = Application.Documents("C:\wordfile.doc")
Dim oExcel As Excel.Application, myWB As Excel.Workbook

Set oExcel = New Excel.Application
Set myWB = oExcel.Workbooks.Open("C:\excelfile.xls")

Dim b As Integer

b = CInt(myWB.Sheets("Sheet1").Range("B20").Value)

For i = 20 To b
oDoc.Bookmarks("bookmark1").Range.Text = myWB.Sheets("Sheet1").Cells(i, 2)

Next i

Set myWB = Nothing
End Sub


Private Sub HideListBoxes()

CommandButton1.Visible = False
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top