what i am doing wrong?

S

stebbix

What I need to do is really simple.. in a powerpoint slide I neeed to be able
to read from txt file with a press of a button and the text appears in a
textbox with scrollbars..
this is the code that iam currently working with.. and it's not working!..
can anybody help me.?

----
Private Sub CommandButton1_Click()

Dim FileNum As Integer
Dim FileName As String
Dim InputBuffer As String
Dim oTextBox As Shape
Dim strText As String

FileName = "C:\atvika_skraning.txt"
FileNum = FreeFile

' A little error checking
If Dir$(FileName) <> "" Then ' the file exists, it's safe to continue
Open FileName For Input As FileNum

While Not EOF(FileNum)
Input #FileNum, InputBuffer
' Do whatever you need to with the contents of InputBuffer
Set oTextBox =
ActiveWindow.Selection.SlideRange.Shapes.AddOLEObject(Left:=114#, _
Top:=48#, _
Width:=522#, _
Height:=450#, _
ClassName:="Forms.TextBox.1", _
Link:=msoFalse)

With oTextBox.OLEFormat.Object
.MultiLine = True
.WordWrap = True
.ScrollBars = fmScrollBarsVertical
.Text = InputBuffer

Wend

Close FileNum
Else
' the file isn't there. Don't try to open it.
End If

End Sub
----
 
S

stebbix

stebbix said:
What I need to do is really simple.. in a powerpoint slide I neeed to be able
to read from txt file with a press of a button and the text appears in a
textbox with scrollbars..
this is the code that iam currently working with.. and it's not working!..
can anybody help me.?

----
Private Sub CommandButton1_Click()

Dim FileNum As Integer
Dim FileName As String
Dim InputBuffer As String
Dim oTextBox As Shape
Dim strText As String

FileName = "C:\atvika_skraning.txt"
FileNum = FreeFile

' A little error checking
If Dir$(FileName) <> "" Then ' the file exists, it's safe to continue
Open FileName For Input As FileNum

While Not EOF(FileNum)
Input #FileNum, InputBuffer
' Do whatever you need to with the contents of InputBuffer
Set oTextBox =
ActiveWindow.Selection.SlideRange.Shapes.AddOLEObject(Left:=114#, _
Top:=48#, _
Width:=522#, _
Height:=450#, _
ClassName:="Forms.TextBox.1", _
Link:=msoFalse)

With oTextBox.OLEFormat.Object
.MultiLine = True
.WordWrap = True
.ScrollBars = fmScrollBarsVertical
.Text = InputBuffer

Wend

Close FileNum
Else
' the file isn't there. Don't try to open it.
End If

End Sub
----

forgot to mention.. the error is something like.. wend cannot come before
while..
 
J

John Wilson

You're missing an "End With"

With oTextBox.OLEFormat.Object
..MultiLine = True
..WordWrap = True
..ScrollBars = fmScrollBarsVertical
..Text = strMessage
End With 'here

Also I think your code will add a new box for each line of the code so you
might want to use something like

While Not EOF(FileNum)
Input #FileNum, InputBuffer
strMessage = strMessage & InputBuffer
Wend
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top