I last touched this code a few months ago, and for some reason it no longer works. When I push a 'commandbutton' in Word it is suppose to extract data from Excel and insert it into Word. However now when i press the 'commandbutton' it appears it just freezes and no data is pressed. both files are in the correct place on my computer to call up.
VB Code:
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
VB Code:
Private Sub HideListBoxes() CommandButton1.Visible = False End Sub




Reply With Quote