Pegasus0990
Technical User
i cannot figure out why my loop is not working properly. all help is greatly appreciated. when a integer replaces the variable "b" in the code, it works fine.
Public Sub CommandButton1_Click()
HideListBoxes
Dim oDoc As Word.Document
Set oDoc = Application.Documents("C:\word.doc")
Dim oExcel As Excel.Application, myWB As Excel.Workbook
Set oExcel = New Excel.Application
Set myWB = oExcel.Workbooks.Open("C:\excel.xls")
Dim b As Integer
b = (myWB.Sheets("Questions").Range("B20").Value)
For i = 20 To b
oDoc.Bookmarks("bookmark1").Range.Text = myWB.Sheets("Questions").Cells(i, 1) + vbNewLine
Next i
Set myWB = Nothing
End Sub
Public Sub CommandButton1_Click()
HideListBoxes
Dim oDoc As Word.Document
Set oDoc = Application.Documents("C:\word.doc")
Dim oExcel As Excel.Application, myWB As Excel.Workbook
Set oExcel = New Excel.Application
Set myWB = oExcel.Workbooks.Open("C:\excel.xls")
Dim b As Integer
b = (myWB.Sheets("Questions").Range("B20").Value)
For i = 20 To b
oDoc.Bookmarks("bookmark1").Range.Text = myWB.Sheets("Questions").Cells(i, 1) + vbNewLine
Next i
Set myWB = Nothing
End Sub